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.
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.
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
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.
One response to “Map Storage Volume with Docker and Windows Containers”
I am running linux containers on windows machine by swithcing the docker engine to run linux containers. but i can’t able to figure out the way to map volume of the linux container with windows(host) file system. but i can map volume of the windows container with the host file system. any help…:)