Docker Storage Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 17: Line 17:
==--mount==
==--mount==


The --mount flag allows mounting data volumes, host directories and tmpfs mounts in a container. --mount supports most of the options supported by [[Docker_Storage_Operations#-v.7C--volume|-v|--volume]], but uses a different syntax.
The --mount flag allows mounting data volumes, host directories and tmpfs mounts in a container. --mount supports most of the options supported by [[Docker_Storage_Operations#-v.7C--volume|-v|--volume]], with some exceptions:
* --mount allows specifying a volume driver and volume driver options per volume, without creating the volume in advance. In contrast, <tt>docker run --volume</tt> allows specifying a single volume driver, which is shared by all volumes, using the --volume-driver flag.
* --mount allows specifying custom metadata ("labels") for a volume, before the volume is created.


  docker run --mount '''type=volume''',source=<''native-host-path''>,destination=<''container-mount-point''>,volume-label="<''some-label''>" ...
  docker run --mount '''type=volume''',source=<''native-host-path''>,destination=<''container-mount-point''>,volume-label="<''some-label''>" ...
Line 27: Line 29:
  docker run ... --mount type=bind,src=/data-volumes/postgresql,dst=/var/lib/pgsql/data ...
  docker run ... --mount type=bind,src=/data-volumes/postgresql,dst=/var/lib/pgsql/data ...


When --mount with type=bind is used, the native-host-path must refer to an existing path on the host. The path will not be created if it does not exist, and the command will fail. Also, the mount point must have sufficient permissions. For more details on native host path permissions, see [[Docker_Storage_Concepts#UID.2FGID_Mapping|Native Host Path Permissions]].
When --mount with type=bind is used, the native-host-path must refer to an existing path on the host. The path will not be created if it does not exist, and the command will fail:
 
docker run --rm -it --mount type=bind,src=/some/path/that/does/not/exist,dst=/blah test-image
docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist.
 
Also, the mount point must have sufficient permissions. For more details on native host path permissions, see [[Docker_Storage_Concepts#UID.2FGID_Mapping|Native Host Path Permissions]].


==-v|--volume==
==-v|--volume==


  docker run ... -v <''native-host-path''>:<''container-mount-point''> ...
  docker run ... -v <''native-host-path''>:<''container-mount-point''> ...

Revision as of 04:13, 9 May 2018

External

Internal

Overview

Container-Generated Data Storage Operations

If the container has volume mount points specified with VOLUME in its original Dockerfile, those mount points must be bound to paths on the native host when the container is created. This is done with --v|--volume or --mount (recommended) command line options, as follows. Note that the mount succeeds even if no VOLUME is declared in Dockerfile.

--mount

The --mount flag allows mounting data volumes, host directories and tmpfs mounts in a container. --mount supports most of the options supported by -v|--volume, with some exceptions:

  • --mount allows specifying a volume driver and volume driver options per volume, without creating the volume in advance. In contrast, docker run --volume allows specifying a single volume driver, which is shared by all volumes, using the --volume-driver flag.
  • --mount allows specifying custom metadata ("labels") for a volume, before the volume is created.
docker run --mount type=volume,source=<native-host-path>,destination=<container-mount-point>,volume-label="<some-label>" ...
docker run ... --mount type=volume,source=/data-volumes/postgresql,destination=var/lib/pgsql/data,volume-label="postgres" ...
docker run ... --mount type=bind,src=<native-host-path>,dst=<container-mount-point> ...
docker run ... --mount type=bind,src=/data-volumes/postgresql,dst=/var/lib/pgsql/data ...

When --mount with type=bind is used, the native-host-path must refer to an existing path on the host. The path will not be created if it does not exist, and the command will fail:

docker run --rm -it --mount type=bind,src=/some/path/that/does/not/exist,dst=/blah test-image
docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist.

Also, the mount point must have sufficient permissions. For more details on native host path permissions, see Native Host Path Permissions.

-v|--volume

docker run ... -v <native-host-path>:<container-mount-point> ...