Map Storage Volume with Docker and Windows Containers

In this blog post, I show you how to mount a Storage Volume to a Windows Server Container using Docker Desktop for Windows on Docker on Windows Server.

Get Started

To get started, I start with Downloading the Windows Nano Server image with PowerShell Core 6.2.

docker pull mcr.microsoft.com/powershell:nanoserver-1803

Create Storage Volume

For a Docker Container to a storage volume, we need to create the volume using the Docker volume command first.

Below, I am creating a volume called psscripts

Docker volume create --name psscripts

In Windows Docker stores all volumes under the path below.

C:\ProgramData\Docker\volumes

Below you can see that my volume was created under the path and it is available for me to access it

Create Container and connect to the volume

Next, I use the command below to create a Container running Windows Nano Server and using the -v switch to map the image inside the container under the c:\psscripts folder.

docker run -it -v c:\programdata\docker\volumes\psscripts:c:\psscripts mcr.microsoft.com/powershell:nanoserver-1803 pwsh

From inside the container I can now see the volume and access directly from the container

Conclusions

Using volumes with Docker and Windows Containers is something any developer and admin need to know for lifecycle management of Containers and apps.

In this post, I used Docker Desktop 18.09 and Windows Nano Server Container image, however, the commands above also work with any Windows Server container image and Linux Containers as well.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.