0

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

Arturo
  • 3,254
  • 2
  • 22
  • 61

1 Answers1

0

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

vijay v
  • 1,888
  • 1
  • 12
  • 19
  • If I do `docker volume create myvolume` where is it created, I mean the path where I can put some data, not `/var/lib/docker/volumes/`? Can I specify the path? – Arturo Mar 30 '20 at 02:50
  • Please check this SO here -- [what-is-the-right-way-to-add-data-to-an-existing-named-volume-in-docker?](https://stackoverflow.com/a/37469637/10363259) – vijay v Mar 30 '20 at 03:05
  • That was not helpful, they are trying to create some container using the same method – Arturo Mar 30 '20 at 03:17
  • if you're taking about pointing a custom directory during docker volume create, you can still do with docker's startup parameters `--data-root`. [Similar SO Link](https://stackoverflow.com/a/52018760/10363259). Does it help? – vijay v Mar 30 '20 at 03:25
  • This is what I'm trying to do: `sudo docker volume create --name my_volume3` and in that parameter include that my files are in `/home/ubuntu/target/` so when I mount later the volume at image creation the container shares the data. So what's the point? I'm creating the volume with my own name and pointing at the destination I have my files (don't confuse with "Mountpoint") – Arturo Mar 30 '20 at 03:28
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/210556/discussion-between-vijay-and-arturo). – vijay v Mar 30 '20 at 03:33