Reputation: 59953
I put one security file like id_rsa
in the docker volume larrycai_vol
, trying to mount this into the container as a file.
$ docker volume inspect larrycai-vol
[
{
"CreatedAt": "2018-05-18T06:02:24Z",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/larrycai-vol/_data",
"Name": "larrycai-vol",
"Options": {},
"Scope": "local"
}
]
Do we have some command like below (it doesn't work now)
docker run -it -v larrycai-vol/id_rsa:/root/.ssh/id_rsa own_ubuntu
I know it works if I mount file from docker host
docker run -it -v $PWD/.ssh/id_rsa:/root/.ssh/id_rsa own_ubuntu
Upvotes: 2
Views: 7450
Reputation: 3691
Please, let me a couple of considerations furthermore the proposed solution to avoid further misunderstandings.
-v $PWD/.ssh:/root/.ssh
= it'd replace complete .ssh folder in destination, so, it's not recommended although possible)-v larrycai-vol:/root/.ssh
= it'd replace complete .ssh folder in destination, so, it's not recommended although possible)-v $PWD/.ssh/id_rsa:/root/.ssh/id_rsa
= your second example)-v /var/lib/docker/volumes/YOUR_NAMED_VOLUME_NAME/_data/file:/dest_dir/file
= what you're trying to do)Your mistake is that you're telling docker to mount id_rsa from your larrycai-vol directory, not from docker named volume. In other words, three following commands are equivalent:
docker run -it -v ./larrycai-vol/id_rsa:/root/.ssh/id_rsa own_ubuntu
docker run -it -v $PWD/larrycai-vol/id_rsa:/root/.ssh/id_rsa own_ubuntu
docker run -it -v larrycai-vol/id_rsa:/root/.ssh/id_rsa own_ubuntu
So, if larrycai-vol directory (not named volume, but directory in your host) doesn't exist, command doesn't work as you want.
Definitively, to do what you're trying you have to create a bind volume
to the directory where named volume store data.
docker run -it -v /var/lib/docker/volumes/larrycai-vol/_data/id_rsa:/root/.ssh/id_rsa own_ubuntu
Upvotes: 6