ealeon
ealeon

Reputation: 12452

"docker volume" vs "docker run -v"

https://docs.docker.com/engine/reference/commandline/volume_create/#driver-specific-options

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

if I create a volume as such, how would I consume it?

docker run -v foo:/foo?

Then, what's the benefits of creating the volume first? couldnt I also do

docker run -v /path/to/dir:/foo?

if /path/to/dir is already NFS mounted on the host?

Upvotes: 0

Views: 752

Answers (1)

Shahriar
Shahriar

Reputation: 13806

Originally, the -v or --volume flag was used for standalone containers and the --mount flag was used for swarm services.

You can also use --mount with standalone containers. In general, --mount is more explicit and verbose.

The biggest difference

  • the -v syntax combines all the options together in one field.
  • the --mount syntax separates them.

If you need to specify volume driver options, you must use --mount

Read details here

Upvotes: 1

Related Questions