The volume management command

Docker has introduced a top-level volume management command from version 1.9 in order to manage the persistent filesystem effectively. The volume management command is capable of managing data volumes that are part of the Docker host. In addition to that, it also helps us to extend the Docker persistent capability using pluggable volume drivers (Flocker, GlusterFS, and so on). You can find the list of supported plugins at https://docs.docker.com/engine/extend/legacy_plugins/.

The docker volume command supports four subcommands as listed here:

  • create: This creates a new volume
  • inspect: This displays detailed information about one or more volumes
  • ls: This lists the volumes in the Docker host
  • rm: This removes a volume

Let's quickly explore the volume management command through a few examples. You can create a volume using the docker volume create subcommand, as shown here:

$ sudo docker volume create
50957995c7304e7d398429585d36213bb87781c53550b72a6a27c755c7a99639

The preceding command will create a volume by autogenerating a 64-hex digit string as the volume name. However, it is more effective to name the volume with a meaningful name for easy identification. You can name a volume using the --name option of the docker volume create subcommand:

$ sudo docker volume create --name example
example

Now, that we have created two volumes with and without a volume name, let's use the docker volume ls subcommand to display them:

$ sudo docker volume ls
DRIVER VOLUME NAME
local 50957995c7304e7d398429585d36213bb87781c53550b72a6a27c755c7a99639
local example

Having listed out the volumes, let's run the docker volume inspect subcommand into the details of the volumes we have created earlier:

$ sudo docker volume inspect example
[
{
"Name": "example",
"Driver": "local",
"Mountpoint":
"/var/lib/docker/volumes/example/_data",

"Labels": {},
"Scope": "local"
}
]

The docker volume rm subcommand enables you to remove the volumes you don't need anymore:

$ sudo docker volume rm example
example

Now that we are familiar with Docker volume management, let's dive deep into data sharing in the ensuing sections.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset