Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give a name to a docker volume mounted from an external drive

I am trying to create a volume on an external drive . It works with the following command

docker run -t -i -v /mnt/mydrive:/var/  ubuntu

But with the above command, I am not able to provide a name to the volume. How can I create a named volume mounted to an external drive?

like image 345
IT_novice Avatar asked Jan 03 '23 18:01

IT_novice


2 Answers

Create a volume and then configure the container to use it:

$ docker volume create my_volume --driver local --opt device=/mnt/mydrive
$ docker run -t -i -v my_volume:/var/  ubuntu

Check docker docs for more options and details.

NB: Drive should be mounted first in your system. But if you want to handle that also through docker, check driver specific options where you can specify ip, write mode, file system etc.

like image 109
Dhia Avatar answered Jan 16 '23 20:01

Dhia


Bind mounts (what you are doing) is not the same as named volumes.

https://docs.docker.com/storage/images/types-of-mounts-bind.png

So you cannot assign a bind mount volume a name.

like image 40
VonC Avatar answered Jan 16 '23 20:01

VonC