[No Audio]
In this demo, we are going to demonstrate the use
of Volumes which we have discussed in the theory.
Let's start with creating the Volume which we had
deleted in the last demo, which is vol-ubuntu.
We will do it by running a container from ubuntu image called cont-ubuntu.
[No Audio]
Let's see if both the Volume and the container are available.
Again, to remind you, we can always check the
container using docker container inspect command
and find the information about Volume by formatting its output.
As you can see, the container called cont-ubuntu
has the Volume vol-ubuntu attached to it.
Now, let's execute our container
and run bash command on it.
You can notice that we are not executing it as a daemon container,
which means that once this command succeeds,
we will jump right into the terminal of our container.
Right now, this container is in its
default state, which means that even if we delete it
and spin it up, again, nothing will change.
So let's make a few changes to it, which will be
reflected in its read-write topmost layer.
And if we delete the container, then the changes we have
made now, would be lost. The action can be pretty
simple here, we don't need to do something so heavy.
Even a simple act of just updating the OS
can create enough changes to be recognized.
So let's update this Ubuntu by typing apt-get update command.
Once it is updated, let's change our
working directory to var-log. As you may
have guessed, this is the directory where ubuntu
is keeping its logs.
Let's list out the available files
and we have a lot of log files here.
The purpose of doing so is, to make sure that once we
stopped the container, we should be able to see
the same files as backup on our host machine.
And the reason for that is when we created this container,
we had mount this directory to our host
using the Volume val-ubuntu.
Let's exit the process and stop the container.
[No Audio]
Now, let's have the root privileges on our host machine.
And as you can see, we are on the same working
directory just with root privileges. Now, as we
have seen in the theory section of Volumes,
Docker stores the backup of Volume data,
under var-lib-docker-volumes directory.
So let's navigate to it and let's list
out the content in this directory. As you can see,
we have directories of all of the Volumes created
by local Volume driver. Now let's navigate to
va-ubuntu to see if the changes in the log
file are reflected. Once we are in vol-ubuntu directory,
let's see its contents, and what we have is a data directory.
Once we navigate to that, and list its contents
what we see is a long list of log files,
which means that the mounting
of Volume with the container was successful.
So this is how we mount a Volume to a
container and create a backup of its data to host
using local Volume driver