Home > Enterprise >  interest of docker create volume command?
interest of docker create volume command?

Time:12-10

i actually play a lot with docker, and i really don't understand the interest of using the command

docker volume create <volume>

In fact, doing this

docker volume create my_data
docker run --rm -ti -v my_data:/src bash

and only this

docker run --rm -ti -v my_data:/src bash

give exactly the same result, as, in the two scenarii, docker

  1. creates the volume

  2. makes the mapping perfectly

So: what is the interest of the 'create' command ?

CodePudding user response:

As @David Maze already said, you can specify non-default volume options with the docker volume create command, such as labels, a custom driver and options for this driver. The documentation has some interesting examples:

For example, the following creates a tmpfs volume called foo with a size of 100 megabyte and uid of 1000.

docker volume create --driver local \
   --opt type=tmpfs \
   --opt device=tmpfs \
   --opt o=size=100m,uid=1000 \
   foo

Another example that uses btrfs:

docker volume create --driver local \
   --opt type=btrfs \
   --opt device=/dev/sda2 \
   foo

Another example that uses nfs to mount the /path/to/dir in rw mode from 192.168.1.1:

docker volume create --driver local \
   --opt type=nfs \
   --opt o=addr=192.168.1.1,rw \
   --opt device=:/path/to/dir \
   foo
  • Related