Search code examples
dockerdocker-composedockerfiledocker-swarm

Docker volume nameing


When I create a volume, the name appears like this: 5feb972bde42aad5df0de56e4b40e92d8b9761164c9dce80c10a0127c44160c4 This is how I'm creating it:

sudo docker run -d -e url=http://example.com --name some-ghost -p 3005:2372 -v "$(pwd)/target":/var/lib/ghost/content ghost:1-alpine

When I inspect it, it shows this:

[
    {
        "CreatedAt": "2020-03-29T20:09:45-04:00",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/5feb972bde42aad5df0de56e4b40e92d8b9761164c9dce80c10a0127c44160c4/_data",
        "Name": "5feb972bde42aad5df0de56e4b40e92d8b9761164c9dce80c10a0127c44160c4",
        "Options": null,
        "Scope": "local"
    }
]

So two things:

  1. How to I know the destination of that volume? For example, I know that one is in /home/ubuntu/target, but if I didn't know, how can I find out?
  2. When I create the volume on the first code above, how can I name the volume so instead of showing a random number as name, I can name it myself?

Thank you


Solution

  • Do a docker volume create myvolume.

    Then with --mount in docker run do,.

    docker run -d  --name test --mount source=myvolume,target=/app image:tab
    

    OR

    With -v in docker run do,.

    docker run -d --name test -v myvolume:/app  image:tag'
    

    You can do a docker inspect on your running container to check the mounts.

    To create a named docker volume wit custom path:

    docker volume create --name myvolume --opt type=none --opt device=/path-you-want-to-mount/ --opt o=bind
    

    Source