Map Storage Volume with Docker and Windows Containers

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

Get Started

To get started, I will 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 voulme 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 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 volumess with Docker and Windows Containers is something any developer and admin need to know for lifecycle managment of Containers and apps.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

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