Volumes for Containers

Search Knowledge Base by Keyword

Volumes for Containers


You can create and manage volumes outside the scope of a container with the docker volume create command. In addition, you can specify a volume in a docker run command by using the -v or --volume flag. If the volume does not yet exist, Docker creates the volume.

You can specify a CIO volume in a docker run command by using the --volume-driver flag to call the cio driver. The example below calls the cio volume plugin to create a volume named foo, for the alpine container.

docker run -it --volume-driver cio -v foo:/tmp --name foo alpine sh

Note that the -v flag does not support volume options. The example above will create a CIO volume with default parameters. At the time of install, the default parameters will create a volume of 20 GB capacity, thin provisioned, mounted at /cio/volumes and with no performance limits.

To specify volume options, you use the --mount flag. Support for using the --mount flag with containers was added in Docker 17.06. The example below produces the same results. Source is the name of the volume and target is the directory mounted in the container.

docker run -it --mount source=foo,target=/tmp,volume-driver=cio --name foo alpine sh

The --mount flag supports the use of volume options. The options are specified as key value pairs. For example

docker run -it \
--mount source=bar,target=/tmp,volume-driver=cio,volume-opt=profile=GOLD \
--name bar alpine sh

This creates a volume named bar with volume options set in profile GOLD. Volume options can also be individually set. For multiple volume options, use comma separation between key value pairs.

docker run -it \
--mount source=foobar,target=/tmp,volume-driver=cio,volume-opt=capacity=88 \
--name foobar alpine sh

The following options are supported by the CIO plugin:

capacity Size in GB 1 to 65536 capacity=25
directory Host path to bind mount /path/to/volume directory=/cio
level Level of data redundancy 2, 3 level=2
type Type of backend storage ssd, hdd type=ssd
iops Performance in min/max IOPS 10 min, 1000000 max iops=100,5000
bandwidth Performance in min/max MB/s thin, thick provision=thick
provision Thick or thin provisioning thin, thick provision=thick
profile Template for volume creation profile name profile=MYSQL


Use docker inspect foobar to verify that the volume above was created and mounted correctly. Look for the Mounts section.

"Mounts": [
        "Type": "volume",
        "Name": "foobar",
        "Source": "/var/lib/docker/plugins/663a4acd7b35a93dd6d76980e60eaad720895a6594
        "Destination": "/tmp",
        "Driver": "cio:latest",
        "Mode": "",
        "RW": true,
        "Propagation": ""

This shows that the mount is a volume, with the source (volume name foobar) a propagated mount from /cio/volumes/vd8 and the mount is readable and writable.


To remove the volume, first stop and remove the container.

$ docker stop bar

$ docker rm bar

$ docker volume rm bar

Explore Further

Docker Storage

Volumes for Services
Volumes for Docker Compose
Volumes and Dockerfiles