Working with docker-compose.yml in Visual Studio 2022 Besides adding a Dockerfile to a project, as we mentioned before, Visual Studio 2017 (from version
15.8 on) can add orchestrator support for Docker Compose to a solution.
When you add container orchestrator support, as shown in Figure 5-7, for the first time, Visual Studio
creates the Dockerfile for the project and creates a new (service section) project in your solution with
several global
docker-compose*.yml
files, and then adds the project to those files. You can then open
the docker-compose.yml files and update them with additional features.
Repeat this operation for every project you want to include in the docker-compose.yml file.
At the time of this writing, Visual Studio supports
Docker Compose orchestrators.
86
CHAPTER 4 | Development process for Docker-based applications
Figure 5-7. Adding Docker support in Visual Studio 2022 by right-clicking an ASP.NET Core project After you add orchestrator support to your solution in Visual Studio, you will also see a new node (in
the
docker-compose.dcproj
project file) in Solution Explorer that contains the added docker-
compose.yml files, as shown in Figure 5-8.
Figure 5-8. The docker-compose tree node added in Visual Studio 2022 Solution Explorer You could deploy a multi-container application with a single docker-compose.yml file by using the
docker-compose up
command. However, Visual Studio adds a group of them so you can override
values depending on the environment (development or production) and execution type (release or
debug). This capability will be explained in later sections.
Step 5. Build and run your Docker application If your application only has a single container, you can run it by deploying it to your Docker host (VM
or physical server). However, if your application contains multiple services, you can deploy it as a
composed application, either using a single CLI command (
docker-compose up)
, or with Visual
Studio, which will us
e that command under the covers. Let’s look at the different options.
87
CHAPTER 4 | Development process for Docker-based applications