Mounting a single file from a Docker data volume in a Docker
Asked Answered
V

1

10

I'm trying to mount a single file from a Docker volume in a container when using "docker run".

I've been able to mount an entire volume as a directory, e.g:

docker run -v my_volume:/root/volume my_container 

I've also mounted single files from the physical machine, e.g:

docker run -v /usr/local/bin/docker:/usr/local/bin/docker 

Is there a way?

Vevine answered 11/4, 2016 at 12:48 Comment(1)
Sure you can docs.docker.com/engine/tutorials/dockervolumes/#/…, but I've been having the same issueImposing
R
4

Is there a way always destination path/file doesn't exist in the container, if you've created a named volume and a bind to its directory (similar to deprecated volumes_from)

docker run -v /var/lib/docker/volumes/my_volume/_data/MY_FILE.txt:/destination_folder/MY_FILE.txt

That's why when you create a named volume and run a service/container with docker run -v my_volume:/root/volume my_container, data is stored in /var/lib/docker/volumes/my_volume/_data

Rearm answered 23/4, 2018 at 10:18 Comment(2)
Is it possible to mount just single file via named volume?Penuche
@EugenKonkov, no, it's not possible. Named volume is always a directory that can contains a single file, but it cannot be a single file itself.Rearm

© 2022 - 2024 — McMap. All rights reserved.