3

It is possible to create docker volume in my destined directory?

I was not able to found it in documentation, I just saw some mountpoints, but I want to mount it localy, from my defined directory. For example /data/docker/volume_name/

docker volume create won't let me do that.

Delirium
  • 1,277
  • 3
  • 16
  • 27
  • 1
    Does this answer your question? [Docker: change folder where to store docker volumes](https://stackoverflow.com/questions/38396139/docker-change-folder-where-to-store-docker-volumes) – J. Scott Elblein Jun 03 '20 at 10:21
  • You should probably use a [bind mount](https://docs.docker.com/storage/bind-mounts/) instead; there aren't really specific advantages to configure a named volume to support this case. The top answer to the linked question has much more detail. – David Maze Jun 03 '20 at 10:26

2 Answers2

6

I don't have enough reputation to comment or flag, but I think your question is already answered here: Docker: change folder where to store docker volumes

In short, see this part of the top answer by BMitch:

docker volume create --driver local \
  --opt type=none \
  --opt device=/home/user/test \
  --opt o=bind \
  test_vol
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
Andruida
  • 334
  • 1
  • 6
1

There is no option out of the box to define directory when creating docker volume. Docker volumes are docker managed and supposed to be isolated from the host operating system interventions. The straightforward answer is to use mount directories if the files are completely managed by you (the host os). If you are dealing with persistent data generated/used by the containers then use docker volumes. This advice comes from docker docs

However if you are insistent on using docker volume that is in defined folder instead of default docker volume directory then this stackexchange post couple of options summarised below;

  1. Use local-persist plugin

sudo docker volume create -d local-persist -o mountpoint=/mnt/ --name=extra-addons

  1. Use symnlinks

docker volume create test mkdir /mnt/test sudo rm -rf /var/lib/docker/volumes/<volume>/_data sudo ln -s /mnt/<myVolume> /var/lib/docker/volumes/<volume>/_data

I personally wouldn't bother with either of them. The advice on docker docs is pretty clear as it can get. If the files are managed by you then use mounted volume or if the files are managed by the container then use docker volume.

madteapot
  • 2,208
  • 2
  • 19
  • 32