Search code examples
dockerdocker-volume

docker run with --volume


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.


Solution

  • 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.

    Example:

    docker run -it -v ${PWD}/scripts:/code/scripts myimage bash