Introduction to Docker volume

A Docker volume is a directory (or collection of files) that lives on the host file system and is not a part of the container’s UFS. It is within these volumes that containers are capable of saving data.

Let’s find out how to deploy a new container that includes a volume attached to a specific directory on a host such that the container will stay in sync with the data in the volume.

Creating the Host Data Volume

The first step is to create a new directory to host the volume. To do this, open a terminal window and issue the command:

mkdir /test

adding /test host data volume to container:

Testing the Volume

Let’s create a test file in that directory with the command:

touch /test/abc.txt

Now this file will be present in the ubuntu container at location /tmp

Task by trainer:

  • Create folder with name /test  on local system. and create “test.txt” in /test folder 
  • Launch  centos container with name “Myapp3” in  detach mode. And  add /test host data volume to  /tmp  folder in centos container.
  • After adding host data volume test.txt file must be present at /tmp folder in centos container.