As can be expected from Microsoft, there is great support for docker built into both VS and VS Code.
I wanted to understand what VS is doing under the hood for us and this post is about that.
I will be using a standard asp.net project in this example. This implies that only windows containers can be targeted for this build. This also needs docker for Windows to be already installed.
When creating the project, we can request a Docker Compose project to be added to the solution.
This adds a docker-compose project and a bunch of files to the solution folder. The following files get added to the root of the solutions directory –
- docker-compose.dcproj – The file representing the project. Includes a <DockerTargetOS> element specifying the OS to be used.
- docker-compose.yml – The docker compose utility can help manage multiple containers and the inter-dependencies. Here we are just building 1 service in a single container. The build section defines the name of the image that will be built based on the context (application build) provided.
version: '3.4' services: dockerex: image: ${DOCKER_REGISTRY-}dockerex build: context: .\DockerEx dockerfile: Dockerfile
- docker-compose.override.yml – An optional file, read by Docker Compose, with configuration overrides for services.
The following files get added to the main project.
- dockerfile
FROM microsoft/aspnet:4.7.2-windowsservercore-1803 ARG source WORKDIR /inetpub/wwwroot COPY ${source:-obj/Docker/publish} .
FROM defines the base image on which the project will be based.
ARG defines that during build an argument named source should be provided.
WORKDIR: since we are targeting a standard asp.net project, we will need IIS and the working dir is defined for it.
Copy: When building the image, it copies the content from the path specified in the source argument to the current directory within the container. If there is no source argument specified, the contents from the path obj/Docker/publish are used.
.dockerignore – Lists the file and directory patterns to exclude when generating a build context.
* !obj\Docker\publish\* !obj\Docker\empty\
So ignore everything except the lines starting with ! (exclamation mark can be used to make exceptions to exclusions).
Recent Comments