How to make volume on a specific path

Working on server i have no rules to read /var/lib directory and it needs to store volume on a specific path, for example in ~/.docker/volumes/volumename. With some magic I have done it yet one times, but forget how for and couldn’t repeat this action. This comand i use to run docker:

docker run --mount type=volume,dst=/usr/src/TrackR-CNN/models,volume-driver=local,volume-opt=type=none,volume-opt=o=bind,volume-opt=device=/home/maker/.docker/volumes/volumename/ --rm -it dockername

You probably don’t need any magic. Did you try

docker run -v /home/maker/.docker/volumes/volumename:/usr/src/TrackR-CNN/models ...

?

No, because i understand how to run docker with volumes, but I need to create volume

And create in the ~/.docker/volumes for example, but not in the /var/lib/docker.

So I don’t understand your question. You have 2 possibilities, either you mount an existing path on your host as a volume, or you create a named volume in Docker. What exactly is your issue with the /home/.../volumename folder?

Yes I need to create a named volume
If i will create volume, it could be placed in /var/lib/docker/volumes/volumename
But i have no rules to write to this directory and i need to story my volume in my home folder ~/.docker/volumes for example, but how i need to use docker volume create to make volume on specific path?

I have created one time volume where in the field “mountpoint”(from result of “docker volume inspect”) was my local way but i forget how i made this and couldn’t repeat

It’s really difficult to understand what you are doing. You speak about named volumes but show commands that create a bind mount. So let’s start with something simple. If you create a named volume with such a compose file, does it work or do you get an error?

---
version: "3"
services:
  web:
    image: httpd
    ports:
      - "8080:80"
    volumes:
      - mydata:/data

volumes:
  mydata:

Yes, this volume will be stored in /var/lib/docker/volumes on a host mashine physically. But how to chose place, whitch will be this volume, because I have no rules to work with /var/…
I can run docker and connect volume into docker, this is no problem, Problem is: I need to place(to store physycally) volume not in the /var, but in /home/…

The forum search for “docker volume create bind” made me find an old post of mine. Plenty of the search results cover the topic…

Here is the syntax on how to create a local named volume that binds a local folder:
docker volume create --opt type=none --opt o=bind --opt device=/data/volumes/testvol testvol

Just replace the path in device= and maybe use a more meaningful name than I did in the example.
The Mounpoint will always be in /var/lib/docker/volumes/{volume name}/_data; there is no way arround that.

2 Likes
docker volume create <volume name> --opt type=none --opt device=<path to volume> --opt o=bind