[No Audio]
In this demo, we are going to create a volume using Docker command line
Let's type the command docker volume create,
followed by the name of the volume.
Here, we are naming the Volume vol-busybox.
Once the commands succeeds, we get the
name of the Volume as the nod of it being created.
Before we do anything to this created Volume,
let's create another one, but this time in a bit
different way. Here, we are going to run a
container using ubuntu image and we're going to
mount the Volume vol-ubuntu on the
containers, tmp or temp directory. Again, we will
not do anything with this Volume, since this demo
primarily focuses on creation of the Volumes.
Now let's list the Volumes to see what we have created.
Let's type docker volume ls, and as you
can see, we have four Volumes here.
Two of them are created by us, whereas two of them are created
by Docker using local Volume driver.
Just like every other object which we have created
previously, like images, networks, or containers,
we can also filter the output of the ls command.
Let's type docker volume ls and put the filter of
dangling=true, it means that it will list
the Volumes which are not being mounted to any container.
Here vol-busybox has not been mounted
to any container. Similarly, the one above it,
which is provisioned by Docker is not being
mounted or used currently. Also, we can inspect
our Volume just like every other object by using
docker volume inspect followed by the volume name.
And as you can see, we get the creation timestamp,
Driver type, Labels which are null here, Mountpoint,
Name of the Volume, and Scope which is local.
Now, let's try to remove one of the Volumes which we have created.
Type the command docker volume rm
followed by the Volume name. Here we are using
Volume vol-ubuntu. As you can see, we get
an error response from Docker daemon. It says that
this Volume can not be removed because it is in use,
which means it has been mount to a container.
So if we remove the Volume,
the container and its performance will be affected.
Let's get a list of containers to see which
container is blocking or action of removing the Volume.
And as you can see, the tender_noyce
container which is built from the ubuntu image,
just two minutes ago, has been mount with the
Volume vol-ubuntu. Although it has not
been mentioned here, you can guess it since all the
other containers are up for more than an hour ago.
Let's type the command docker container rm
followed by its name and tender_noyce is removed.
Now let's rerun the command docker volume rm vol-ubuntu.a
This time, we didn't see any error
and the Volume should have been removed.
Let's verify it by listing the Volumes again.
And yes, the vol-ubuntu is not visible