Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mounting a single file from a Docker data volume in a Docker

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?

like image 918
ateles Avatar asked Apr 11 '16 12:04

ateles


People also ask

Can I mount a single file Docker?

The Docker CLI provides the –mount and –volume options with a run command to bind a single file or directory.

Can you share data between Docker containers using Docker volume?

Multiple containers can run with the same volume when they need access to shared data. Docker creates a local volume by default. However, we can use a volume diver to share data across multiple machines. Finally, Docker also has –volumes-from to link volumes between running containers.

What are the two types of mounts in Docker?

Bind mounts and named volumes are the two main types of volumes that come with the Docker engine. However, additional volume drivers are available to support other use cases (SFTP, Ceph, NetApp, S3, and more).


1 Answers

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

like image 146
Alejandro Galera Avatar answered Sep 19 '22 02:09

Alejandro Galera