Customize container volume mapping
For debugging to work in containers, Visual Studio uses volume mapping to map the debugger and NuGet folders from the host machine. Volume mapping is described in the Docker documentation here. You can view the volume mappings for a container by using the Containers window in Visual Studio.
Prerequisites
- Docker Desktop
- Visual Studio 2019 or later with the Web Development, Azure Tools workload, and/or .NET desktop development workload installed
Volume mounts in Visual Studio container images
Here are the volumes that are mounted in your container:
Volume | Description |
---|---|
App folder | Contains the project folder where the Dockerfile is located. |
NuGet packages folders | Contains the NuGet packages and fallback folders that are read from the obj{project}.csproj.nuget.g.props file in the project. |
Remote debugger | Contains the bits required to run the debugger in the container depending on the project type. See Customize container images for debugging. |
Source folder | Contains the build context that is passed to Docker commands. |
Here are the volumes that are mounted in your container. What you see in your containers might differ depending on the minor version of Visual Studio 2022 you are using.
Volume | Description |
---|---|
App folder | Contains the project folder where the Dockerfile is located. |
NuGet packages folders | Contains the NuGet packages and fallback folders that are read from the obj{project}.csproj.nuget.g.props file in the project. |
Remote debugger | Contains the bits required to run the debugger in the container depending on the project type. For more information, see Customize container images for debugging. |
Source folder | Contains the build context that is passed to Docker commands. |
VSTools | Contains Visual Studio tools that support working with the container, including support for the debugger, the Containers window, handling Azure tokens, the Hot Reload agent, and the Distroless Helper. |
For .NET 8, additional mount points at root and for the app user that contain user secrets and the HTTPS certificate might also be present.
Note
Visual Studio 17.10 If you're using Docker Engine in Windows Subsystem for Linux (WSL) without Docker Desktop, set the environment variable VSCT_WslDaemon=1
to have Visual Studio use WSL paths when creating volume mounts. The NuGet package Microsoft.VisualStudio.Azure.Containers.Tools.Targets 1.20.0-Preview 1 is also required.
For ASP.NET core web apps, there might be two additional folders for the SSL certificate and the user secrets, which is explained in more detail at Use SSL for containerized ASP.NET Core apps
Mount a container volume
You can mount another volume using docker run
command-line arguments.
Open the project file for the containerized project.
To specify a new command-line argument, add the MSBuild property
DockerfileRunArguments
, and provide the-v
or--mount
syntax. For example, the following syntax creates a volumemyvolume
and mounts it in the container in the folder/scratch
.<PropertyGroup> <DockerfileRunArguments>-v myvolume:/scratch</DockerfileRunArguments> </PropertyGroup>
Refer to the Docker documentation for the command-line syntax for the -v or --mount options.