Creating Container Volumes In Windows 2016

Creating container volume

Creating container volumes in windows 2016

In this blog, we will share you creating container volumes in windows 2016 using docker commands.

OVERVIEW

In addition, to store the data inside the container while building, we can also set it up the container to access the data outside their environment. For example, create a folder on container host and we can access the folder from inside the container.

CREATING CONTAINER FOLDER

  • Create a folder in C:\ drive named containerdata using below command.

mkdir containerdata

Creating container volumes in windows 2016
  • Create two new files named file1.txt and file2.txt
Creating container volumes in windows 2016

LAUNCHING NEW CONTAINER AND MAP THE FOLDER

  • Create a new container along with mapping using below command.

SYNTAX :  docker run -it -v <sourcefolderpath>:<destination folder path where source folder to be mounted> <container OS image< <process to kickstart during creation>

EXAMPLE: docker run -it -v c:\containerdata:c:\mydata azcontainerr/web powershell

docker – Base command for docker command line interface.

-it – To start the docker container in interactive mode.

-v – to map the local folder (or) data volume to a folder inside the container.

c:\containerdata – It’s the source folder from the container host

c:\mydata – Define the path where the source folder to be mounted.

azcontainerr/web – Image to start the container

PowerShell – To kickstart the PowerShell process inside the container.

Creating container volumes in windows 2016
  • Once the container up and running, List the files and folders to verify mydata folder is available.
Creating container volumes in windows 2016
  • If we list the files inside mydata, we can see our files file1.txt and file2.txt.
Creating container volumes in windows 2016
  • Create a new file inside the mydata folder using below command.

New-Item -ItemType file -Name file3.txt -Value ‘container text’

Creating container volumes in windows 2016
  • List the directory and we can able to find the third file in the list.
Creating container volumes in windows 2016
  • We can able to see the file from the container host.
Creating container volumes in windows 2016
  • Quit from the container using below command.

exit

Creating container volumes in windows 2016
  • Now container is in stopped mode. We can verify it using docker ps –a command.
Creating container volumes in windows 2016

REMOVING CONTAINER

  • Now delete the container using rm command.

docker rm 9d

Creating container volumes in windows 2016
  • There are no containers available now.
Creating container volumes in windows 2016
  • You can see all three files available in the c:\containerdata folder from the container host
Creating container volumes in windows 2016
  • The data are available after we delete the containers.

CREATING PERSISTENT DATA VOLUMES

  • We can create persistent data volumes that can be shared access multiple containers. It’s like virtual volume which can be connected to different containers.
  • To create persistent data volume, use the below command.

SYNTAX: docker run -it -v <data volume name>:<Folder name where data volume to be mounted> <container image name> <command to kickstart the process>

EXAMPLE: docker run -it -v mydata:c:\demo azcontainerr/web powershell

docker – Base command for docker command line interface.

-it – To start the docker container in interactive mode.

-v – to map the local folder (or) data volume to a folder inside the container.

mydata – create a data volume

c:\demo – where data volume should be mounted inside the container

azcontainerr/web – Image to start the container

powershell – To kickstart the PowerShell process inside the container.

Creating container volumes in windows 2016
  • Once the container is up and running, list the folders to verify demo folder is available.
Creating container volumes in windows 2016
  • There is no files are available under demo folder.
Creating container volumes in windows 2016
  • Create a new file named test.txt using below command.

New-Item -Itemtype file -Name test.txt -Value ‘hello assistanz’

Creating container volumes in windows 2016
  • Now disconnect this container by pressing CTRL+PQ keys.
Creating container volumes in windows 2016
  • Make sure that container is in running state by executing docker ps command.
Creating container volumes in windows 2016
  • Launch a new container with same volume mapping using below command.

docker run -it -v mydata:c:\demo azcontainerr/web powershell

Creating container volumes in windows 2016
  • Once container up and running, list the folders to view demo folder.
Creating container volumes in windows 2016
  • If we list inside the demo folder, we can see the text file which we created from the other container.
Creating container volumes in windows 2016
  • Disconnect from this container by pressing CTRL+PQ keys.
Creating container volumes in windows 2016

ABOUT DATA VOLUMES

  • Actually, we create, manage and delete data volumes using docker volume command.
  • To list the available data volumes in the container host, use the below command.

docker volume ls

Creating container volumes in windows 2016
  • Make sure that container is deleted prior to delete volumes. To delete multiple containers, use the below command.

docker rm –f $(docker ps -q)

Creating container volumes in windows 2016
  • To delete the docker volume, execute the below command.

SYNTAX: docker volume rm <volume name>

COMMAND : docker volume rm mydata

Creating container volumes in windows 2016
  • You can verify the data volumes using docker volume ls command.
Creating container volumes in windows 2016
VIDEO

Thanks for reading this blog. We hope it was useful for you to learn how to share the folders and data volumes inside the container(s).

Loges