Use of VS2017 docker deployment tool

**A brief description:**

- The docker support tool of VS2017 supports .Net Framework, .Net Core console or web application to generate, debug and run in docker. For .Net Framework, it supports windows containers and images, and for .Net Core applications, it supports linux containers and images. The VS2017 Preview version supports both linux and windows containers and images for .Net Core.


**Environment preparation:**
```
Install docker for windows, the installation steps refer to the previous [Docker installation process]
to configure a private warehouse in docker, Setting->Daemon->Insecure registries fill
in the private warehouse url and configure sharing in docker Disk, used to store containers. Generally shared C drive, Setting->Shared Drives

````

**Create a .Net Core Web project:**
- .Net Core Web itself can be run in the console mode, which is similar to the operating principle of the api framework we use.
- .After creating the project, select Project->Add->Docker Support


- .After adding [docker support] to the project, a docker-compose project will be added. In the docker-compose project, some .yml files are generated. And in the [WebApplication2] project, a DockerFile file was added.

**docker-compose introduction:**
- .docker-compose is a tool used to define and run complex applications in Docker, and it is now integrated into VS.
1. The relationship between docker-compose and VS solutions
```
A solution corresponds to a docker-compose project, which consists of docker-compose.yml and its sub-file components, and sub-files are used to supplement it!
````
2. The relationship between docker-compose and VS and projects
```
A docker-compose includes all projects that can be published, and these projects are called a service in compose!
````
3. The relationship between Dockerfile and VS project
````
A Dockerfile corresponds to a specific project, which can be a website, API, console program, etc., mainly to publish and run them!
```` 4.
The relationship between docker-compose and Dockerfile```` A docker-compose will include multiple Dockerfiles, and each Dockerfile corresponds to an image, that is, many images are composed of a service, a docker-compose, We can divide services according to our own rules. The smallest management unit of docker-compose is "service"! ```` 5. The role of each .yml file`` docker-compose.ci.build.yml defines the ci command to compile the project, the basic image version






docker-compose.yml defines a set of images corresponding to a project, the DockerFile path and name corresponding to the image
docker-compose.override.yml defines environment variables, and the mapping port
docker-compose.vs.debug.yml of the host is defined in docker-compose.vs.debug.yml The configuration of docker compilation in debug mode
docker-compose.vs.release.yml defines the configuration of docker compilation in release mode. For
details about the .yml file, please refer to the following URL:
http://www.cnblogs.com/ freefei/p/5311294.html
````

**DockerFile introduction:**
- .DockerFile defines the process of compiling a project into an image.
```
For more information about DockerFile, please refer to the following URL:
http://blog.csdn.net/wsscy2004/article/details/25878223
```

**Debug project in the Docker environment:**
1. Select docker-compose and set it as the startup project
2. Switch the local docker to the linux container mode
4. Set the debug mode
5. Press f5 in VS to run the project, you You can see the entire compilation process in the "output" of VS, and the process of compiling the project into an image, generating a container, and running the container.
6. In powershell, execute "docker ps" to see that a container is running.


7. In powershell, execute "docker images" to see the newly generated image.


8. The name and tag of the new image are defined in docker-compose.vs.debug.yml, which can be modified in the file.


9. Set a breakpoint in the VS project, and visit the page that is already running. If it is an interface, visit the interface to debug the program.


10. During the debugging process, if a problem is found and the code is modified, as long as f5 is re-run, the new image and container will be automatically compiled in docker.
11. It should be emphasized here that the image generated under debug is not a usable image, because it can only be used by vs. If you use "docker run" manually, you cannot generate the container.

**Release project in Docker environment:**
1. If there is no problem under debug, then you can release the project to docker for testing or release
2. Under Release, it is mainly in docker-compose.vs. Configured in the file release.yml, the name and tag of the generated image can be changed. It should be noted here that even if the address of the private repository is added to the image name [private repository address: port]\imageName: tag, after the image is compiled successfully , it will not be automatically pushed to the private repository.
3. Set Release mode
4. Press f5 in vs to run, after success, you can see that the corresponding image has been successfully generated.


5. Because vs integrates the function of docker-compose, through powershell, cd to the directory where the docker-compose file of the project is located, and run docker-compose build to successfully generate images. More knowledge about docker-compose commands can be found , reference: http://www.cnblogs.com/52fhy/p/5991344.html

**Push the image to the private repository and publish:**
1. Push the generated image to the private repository via "docker push".
2. In the test environment, pull the image to it through "docker pull", and run it, you can access it.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325347594&siteId=291194637