dockercontainersvolumes

When using docker run, how do I specify whether I intend to use a named volume or a bind mount?


Given the following command docker run -v value-a:some/dir my-image, will docker mount a volume named value-a or mount the directory value-a found on the host machine? How does docker run differentiate between volumes and bind mounts?


Solution

  • Bind mount paths have to be absolute on the docker run command, so in your case, it'll create a volume since value-a isn't an absolute path. To have it bind to the directory, you'd use something like

    docker run -v $(pwd)/value-a:some/dir my-image