Reading Time: < 1 minute

Mounting Volumes in Docker with Visual Studio

This technique is ideal for local development within Visual Studio. You can easily mount local files into a docker container by modifying the MSBuild commands of the project.

Project File’s MSBuild Commands

This code came from a .NET Core 3.1 project.

Docker Volume Mounting

The docker -v or –volume flag is used to designate a volume mount in a Docker command. There’s another way to mount volumes using the “–mount” flag. This originally was only for Docker swarm environments but since the release of Docker 17.06 this can be used in standalone containers. The “–mount” command is specifically used with mounting services.

# mounting an existing container
docker run -v C:\data:/data

Read Only Access

If you want to restrict access to read only… modify the flag to look like this “-v C:\data:/data:ro

You can read more about Docker volume mounting here.