docker run with --volume

planetp picture planetp · Dec 15, 2017 · Viewed 38.1k times · Source

I'm trying to dockerize some services for development on my machine and wondering how docker run --volume=.. works. For example, if I do something like

docker run --volume=/path/to/data:/data [...]

will /path/to/data be (re)created locally only if it doesn't exist? Is the initial data copied from the container's image?
Links to relevant documentation would be appreciated.

Answer

Oliver Charlesworth picture Oliver Charlesworth · Dec 15, 2017

The --volume option is described in the docker run reference docs, which forwards you on to the dedicated Managed data in containers docs, which then forwards you on to the Bind mounts docs.

There, it says:

If you use -v or --volume to bind-mount a file or directory that does not yet exist on the Docker host, -v will create the endpoint for you. It is always created as a directory.