How To Use DockerFile To Create A Volume With Windows Containers

In this blog post, I’ll show you how to create a volume from a DockerFile and make It available every time creating a container using the Image.  

Mounting volumes In Containers Is very Important because It gives us the ability to copy, store and backup data from and to running containers.

Containers are not designed to store or keep data Inside them so It’s very important to make sure that Important data Is stored outside the Container.

In the past I’ve blogged about copying data to Windows Containers, This article will add another method.

DockerFile

In the example below, I have a very simple DockerFile with that will build an Image using Nano Server.

In the second line, I’m using the VOLUME command to create a Volume on the container host In following page c:\programdata\docker\volumes

Build Image

Below, I’ll use the docker build command to build the Image

docker build -t volume .

Create Container

Once done, I’ll create a new Container from the Image.

docker run --rm -it --name web001 volume:latest powershell

At the same time, docker will create a folder with the Container’s name Inside the Volume folder.

Below, you can see the volume I created In the DockerFile (Called data) and I’ll go ahead and create a file Inside it.

And as you can see below, The file was created on the Container Host and not Inside the Container

 

Leave a Reply

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