Scaling each service is done using Docker Compose, for example type docker-compose scale test-app=4 to have 4 instances of application “test” running. Those instances will be automatically load-balanced by the gateway(s), and will automatically join the same Hazelcast cluster (if Hazelcast is your Hibernate 2nd-level cache). A Windows host has no problem running Linux containers but Docker Compose does not automatically support multi-platform hosts. The platform configuration option was added to Docker Compose files starting with version 2.4 and then removed beginning with version 3.x.

–>

The developer workflow when using the Docker Tools included in Visual Studio 2017 version 15.7 and later, is similar to using Visual Studio Code and Docker CLI (in fact, it”s based on the same Docker CLI), but it”s easier to get started, simplifies the process, and provides greater productivity for the build, run, and compose tasks. It can also run and debug your containers via the usual F5 and Ctrl+F5 keys from Visual Studio. You can even debug a whole solution if its containers are defined in the same docker-compose.yml file at the solution level.

Configure your local environment

With the latest versions of Docker for Windows, it”s easier than ever to develop Docker applications because the setup is straightforward, as explained in the following references.

Tip

To learn more about installing Docker for Windows, go to (https://docs.docker.com/docker-for-windows/).

Docker support in Visual Studio

There are two levels of Docker support you can add to a project. In ASP.NET Core projects, you can just add a Dockerfile file to the project by enabling Docker support. The next level is container orchestration support, which adds a Dockerfile to the project (if it doesn”t already exist) and a docker-compose.yml file at the solution level. Container orchestration support, via Docker Compose, is added by default in Visual Studio 2017 versions 15.0 to 15.7. Container orchestration support is an opt-in feature in Visual Studio 2017 versions 15.8 or later. Visual Studio 2019 and later supports Kubernetes/Helm deployment as well.

The Add > Docker Support and Add > Container Orchestrator Support commands are located on the right-click menu (or context menu) of the project node for an ASP.NET Core project in Solution Explorer, as shown in Figure 4-31:

Figure 4-31. Adding Docker support to a Visual Studio 2019 project

Add Docker support

Besides the option to add Docker support to an existing application, as shown in the previous section, you can also enable Docker support during project creation by selecting Enable Docker Support in the New ASP.NET Core Web Application dialog box that opens after you click OK in the New Project dialog box, as shown in Figure 4-32.

Figure 4-32. Enable Docker support during project creation in Visual Studio 2019

When you add or enable Docker support, Visual Studio adds a Dockerfile file to the project, that includes references to all required project from the solution.

Add container orchestration support

Network

When you want to compose a multi-container solution, add container orchestration support to your projects. This lets you run and debug a group of containers (a whole solution) at the same time if they”re defined in the same docker-compose.yml file.

To add container orchestration support, right-click on the solution or project node in Solution Explorer, and choose Add > Container Orchestration Support. Then choose Kubernetes/Helm or Docker Compose to manage the containers.

Compose

After you add container orchestration support to your project, you see a Dockerfile added to the project and a docker-compose folder added to the solution in Solution Explorer, as shown in Figure 4-33:

Figure 4-33. Docker files in Solution Explorer in Visual Studio 2019

If docker-compose.yml already exists, Visual Studio just adds the required lines of configuration code to it.

Configure Docker tools

From the main menu, choose Tools > Options, and expand Container Tools > Settings. The container tools settings appear.

Windows Docker Compose Volume Path

Figure 4-34. Docker Tools Options

Filezilla download mac os. FileZilla is a free FTP client which is available for most of the popular operating systems including Windows, Linux, and Mac OS. In order to use this FTP client, follow these steps: Download FileZilla to your local computer from the official project page at.

The following table might help you decide how to set these options.

Page/Setting Default Setting Description
General page
Install Docker Desktop if needed Prompt me
Start Docker Desktop if needed Prompt me
Trust ASP.NET Core SSL certificate Prompt me If the localhost SSL certificate hasn”t been marked as trusted (with dotnet dev-certs https --trust), Visual Studio will prompt every time you run your project.
Single Project page
Pull required Docker images on project open True For increased performance when running the project, Visual Studio will start a Docker pull operation in the background so that when you”re ready to run your code, the image is already downloaded or in the process of downloading. If you”re just loading projects and browsing code, you can turn this off to avoid downloading container images you don”t need. This could slow the open project user experience.
Pull updated Docker images on project load .NET Core projects Pull updates to existing images to get the latest updates on project open. This could slow the open project user experience.
Remove containers on project close True Clean up on project close, This could slow the close project user experience but it”s usually fast anyway.
Run containers on project open True For increased performance when running the project, Visual Studio will start all containers in the solution. This could slow the open project user experience.
Docker Compose The Docker Compose page contains the same settings as the Single Project page, but they apply to multi-container solutions.

Warning

If the localhost SSL certificate is not trusted, and you set the option to Never, then HTTPS web requests might fail at runtime in your app or service. In that case, set the value back again to Prompt me or, better again, trust the certificates in your dev machine using the command dotnet dev-certs https --trust.

Tip

For further details on the services implementation and use of Visual Studio Tools for Docker, read the following articles:

Debug apps in a local Docker container: /visualstudio/containers/edit-and-refresh

Deploy an ASP.NET container to a container registry using Visual Studio: /visualstudio/containers/hosting-web-apps-in-docker

Docker Compose provides a way to orchestrate multiple containers that work together. Examples include a service that processes requests and a front-end web site, or a service that uses a supporting function such as a Redis cache. If you are using the microservices model for your app development, you can use Docker Compose to factor the app code into several independently running services that communicate using web requests. This article helps you enable Docker Compose for your apps, whether they are Node.js, Python, or .NET Core, and also helps you configure debugging in Visual Studio Code for these scenarios.

Also, for single-container scenarios, using Docker Compose provides tool-independent configuration in a way that a single Dockerfile does not. Configuration settings such as volume mounts for the container, port mappings, and environment variables can be declared in the docker-compose YML files.

To use Docker Compose in VS Code using the Docker extension, you should already be familiar with the basics of Docker Compose.

Adding Docker Compose support to your project

If you already have one or more Dockerfiles, you can add Docker Compose files by opening the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)), and using the Docker: Add Docker Compose Files to Workspace command. Follow the prompts.

You can add Docker Compose files to your workspace at the same time you add a Dockerfile by opening the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)) and using the Docker: Add Docker Files to Workspace command. You”ll be asked if you want to add Docker Compose files. If you want to keep your existing Dockerfile, choose No when prompted to overwrite the Dockerfile.

The Docker extension adds the docker-compose.yml file to your workspace. This file contains the configuration to bring up the containers as expected in production. In some cases, a docker-compose.debug.yml is also generated. This file provides a simplified mode for starting that enables the debugger.

The VS Code Docker extension generates files that work out of the box, but you can also customize them to optimize for your scenario. You can then use the Docker Compose Up command (right-click on the docker-compose.yml file, or find the command in the Command Palette) to get everything started at once. You can also use the docker-compose up command from the command prompt or terminal window in VS Code to start the containers. Refer to the Docker Compose documentation about how to configure the Docker Compose behavior and what command-line options are available.

With the docker-compose files, you can now specify port mappings in the docker-compose files, rather than in the .json configuration files. For examples, see the Docker Compose documentation.

Tip: When using Docker Compose, don”t specify a host port. Instead, let the Docker pick a random available port to automatically avoid port conflict issues.

Add new containers to your projects

If you want to add another app or service, you can run Add Docker Compose Files to Workspace again, and choose to overwrite the existing docker-compose files, but you”ll lose any customization in those files. If you want to preserve changes to the compose files, you can manually modify the docker-compose.yml file to add the new service. Typically, you can cut and paste the existing service section and change the names as appropriate for the new service.

You can run the Add Docker Files to Workspace command again to generate the Dockerfile for a new app. While each app or service has its own Dockerfile, there”s typically one docker-compose.yml and one docker-compose.debug.yml file per workspace.

In Python projects, you have the Dockerfile, .dockerignore, docker-compose*.yml files all in the root folder of the workspace. When you add another app or service, move the Dockerfile into the app”s folder.

In Node.js projects, the Dockerfile and .dockerignore files will be next to the package.json for that service.

For .NET, the folder structure is already set up to handle multiple projects when you create the Docker Compose files, .dockerignore and docker-compose*.yml are placed in the workspace root (for example, if the project is in src/project1, then the files are in src), so when you add another service, you create another project in a folder, say project2, and recreate or modify the docker-compose files as described previously.

Debug

First, refer to the debugging documentation for your target platform, to understand the basics on debugging in containers with VS Code:

If you want to debug in Docker Compose, run the command Docker Compose Up using one of the two Docker Compose files as described in the previous section, and then attach using the appropriate Attach launch configuration. Launching directly using the normal launch configuration does not use Docker Compose.

Create an Attachlaunch configuration. This is a section in launch.json. The process is mostly manual, but in some cases, the Docker extension can help by adding a pre-configured launch configuration that you can use as a template and customize. The process for each platform (Node.js, Python, and .NET Core) is described in the following sections.

Node.js

  1. On the Debug tab, choose the Configuration dropdown, choose New Configuration and select the Docker Attach configuration template Node.js Docker Attach (Preview).

  2. Configure the debugging port in docker-compose.debug.yml. This is set when you create the file, so you might not need to change it. In the example below, port 9229 is used for debugging on both the host and the container.

  3. If you have multiple apps, you need to change the port for one of them, so that each app has a unique port. You can point to the right debugging port in the launch.json, and save the file. If you omit this, the port will be chosen automatically.

    Here”s an example that shows the Node.js launch configuration – Attach:

  4. When done editing the Attach configuration, save launch.json, and select your new launch configuration as the active configuration. In the Debug tab, find the new configuration in the Configuration dropdown.

  5. Right-click on the docker-compose.debug.yml file and choose Compose Up.

  6. When you attach to a service that exposes an HTTP endpoint that returns HTML, the web browser doesn”t open automatically. To open the app in the browser, choose the container in the sidebar, right-click and choose Open in Browser. If multiple ports are configured, you”ll be asked to choose the port.

  7. Launch the debugger in the usual way. From the Debug tab, choose the green arrow (Start button) or use F5.

Python

For debugging Python with Docker Compose, follow these steps:

  1. On the Debug tab, choose the Configuration dropdown, choose New Configuration, choose Python, and select the Remote Attach configuration template.

  2. You”ll be prompted to choose the host machine (for example, localhost) and port you want to use for debugging. The default debugging port for Python is 5678. If you have multiple apps, you need to change the port for one of them, so that each app has a unique port. You can point to the right debugging port in the launch.json, and save the file. If you omit this, the port will be chosen automatically.

  3. When done editing the Attach configuration, save the launch.json. Navigate to the Debug tab and select Python: Remote Attach as the active configuration.

  4. If you already have a valid Dockerfile, we recommend running the command Docker: Add Docker Compose Files to Workspace. This will create a docker-compose.yml file and also a docker-compose.debug.yml, which volume maps and starts the Python debugger in the container. If you do not have a Dockerfile already, we recommend running Docker: Add Docker Files to Workspace and selecting Yes to include Docker Compose files.

    Note: By default, when using Docker: Add Docker Files to Workspace, choosing the Django and Flask options will scaffold a Dockerfile configured for Gunicorn. Follow the instructions in the Python in a container quickstart to ensure it is configured properly before proceeding.

  5. Right-click on the docker-compose.debug.yml file (example shown below) and choose Compose Up.

  6. Once your container is built and running, attach the debugger by hitting F5 with the Python: Remote Attach launch configuration selected.

    Note: If you would like to import the Python debugger into a specific file, more information can be found in the debugpy README.

  7. When you attach to a service that exposes an HTTP endpoint and returns HTML, the web browser may not open automatically. To open the app in the browser, right-click the container in the Docker Explorer and choose Open in Browser. If multiple ports are configured, you”ll be asked to choose the port. Download font to word mac.

    You”re now debugging your running app in the container.

.NET

Windows Docker Compose File

  1. On the Debug tab, choose the Configuration dropdown, choose New Configuration and select the Docker Attach configuration template .NET Core Docker Attach (Preview).

  2. VS Code tries to copy vsdbg from the host machine to the target container using a default path. You can also provide a path to an existing instance of vsdbg in the Attach configuration.

  3. When done editing the Attach configuration, save launch.json, and select your new launch configuration as the active configuration. In the Debug tab, find the new configuration in the Configuration dropdown.

  4. Right-click on the docker-compose.debug.yml file and choose Compose Up.

  5. When you attach to a service that exposes an HTTP endpoint that returns HTML, the web browser doesn”t open automatically. To open the app in the browser, choose the container in the sidebar, right-click and choose Open in Browser. If multiple ports are configured, you”ll be asked to choose the port.

  6. Launch the debugger in the usual way. From the Debug tab, choose the green arrow (Start button) or use F5.

  7. If you try to attach to a .NET Core app running in a container, you”ll see a prompt ask to select your app”s container.

    To skip this step, specify the container name in the Attach configuration in launch.json:

    Next, you”re asked if you want to copy the debugger (vsdbg) into the container. Choose Yes.

If everything is configured correctly, the debugger should be attached to your .NET Core app.

Recently, I was validating if Windows 10 could become my new main operating system. Recent releases such as Windows Subsystem for Linux (WSL) in version 2 made me think about switching from macOS to Windows. I experienced strange issues while trying to build my blog (using the jekyll/jekyll Docker image) on Windows 10 in WSL2. Image Docker Desktop introduces a new onboarding tutorial upon first startup. The Quick Start tutorial guides users to get started with Docker in a few easy steps. It includes a simple exercise to build an example Docker image, run it as a container, push and save the image to Docker Hub. For more on this issue, see How to set up Docker within Windows System for Linux (WSL2) on Windows 10. Trouble finding docker image storage folder. Docker creates two distro folders to store data: wsl$ docker-desktop wsl$ docker-desktop-data. Docker in Docker! Microsoft Ignite Microsoft’s annual gathering of technology leaders and practitioners delivered as a digital event experience this March.

Volume mounts

By default, the Docker extension does not do any volume mounting for debugging components. There”s no need for it in .NET Core or Node.js, since the required components are built into the runtime. If your app requires volume mounts, specify them by using the volumes tag in the docker-compose*.yml files.

Docker Compose with multiple Compose files

Workspaces can have multiple docker-compose files to handle different environments like development, test, and production. The content of the configuration can be split into multiple files. For example, a base compose file that defines the common information for all environments and separate override files that define environment-specific information. When these files are passed as input to the docker-compose command, it combines these files into a single configuration. By default, the Docker: Compose Up command passes a single file as input to the compose command, but you can customize the compose up command to pass in multiple files using command customization. Or, you can use a custom task to invoke the docker-compose command with the desired parameters.

Note: If your workspace has docker-compose.yml and docker-compose.override.yml and no other compose files, then the docker-compose command is invoked with no input files and it implicitly uses these files. In this case, no customization is needed.

Command customization

Command customization provides various ways to customize the compose up command based on your requirements. The following are few sample command customization for the compose up command.

Base file and an override file

Let”s assume your workspace has a base compose file (docker-compose.yml) and an override file for each environment (docker-compose.dev.yml, docker-compose.test.yml and docker-compose.prod.yml) and you always compose up with the base file and an override file. In this case, the compose up command can be customized as in the following example. When the compose up command is invoked, the ${configurationFile} is replaced by the selected file.

Template matching

Let”s assume you have different set of input files for each environment. You could define multiple templates with regular expression match, and the selected file name will be matched against this match property and the corresponding template will be used.

Pick a template when the command is invoked

If you omit the match property from command templates, you will be asked which template to use each time compose up command is invoked. For example:

Custom tasks

Windows Docker Compose Example

Rather than use command customization, you can also define a task like the following to invoke a docker-compose command. Please refer custom task for more detail on this.

Windows Install Docker-compose

Next steps