Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker inside docker : volume is mounted, but empty

I am running a docker container with docker mounted inside using :

docker run -v /Path/to/service:/src/service -v /var/run/docker.sock:/var/run/docker.sock --net=host image-name python run.py

This runs a python script that creates a data folder in /src and fills it. When printing os.listdir('/src/data'), I get a list of files.

I then run a container from within this container, mounting the data folder, using docker-py.

volumes = {'/src/data': {'bind': '/src', 'mode': 'rw'}}    
client.containers.run(image, command='ls data', name=container_key, network='host', volumes=volumes)

And it prints :

Starting with UID: 0 and HOME: /src\n0\n'

Which means data is mounted, but empty. What am I doing wrong ?

like image 339
user6403833 Avatar asked Jun 21 '18 14:06

user6403833


People also ask

What is the difference between volume and mount in docker?

The most notable difference between the two options is that --mount is more verbose and explicit, whereas -v is more of a shorthand for --mount . It combines all the options you pass to --mount into one field. On the surface, both commands create a PostgreSQL container and set a volume to persist data.

How do I get rid of unused docker volumes?

Volumes are removed using the docker volume rm command. You can also use the docker volume prune command.

What does mounting a volume mean in docker?

The VOLUME command will mount a directory inside your container and store any files created or edited inside that directory on your hosts disk outside the container file structure, bypassing the union file system.

How do I mount a volume in running docker container?

Cloning From An Existing Container But, if you do need to add a volume to a running container, you can use docker commit to make a new image based on that container, and then clone it with the new volume. Then, you can run the new image, replacing the old image with the cloned one.


1 Answers

So- mounting docker inside the container means that containers started from in there are running on your HOST machine.

The end result is you have two containers on host- one with /Path/to/service:/src/service and one with /src/data:/src

If you want to share a volume between two containers you should usually use a "named" volume like docker run -v sharedvolume:/src/data and docker run -v sharedvolume:/src

like image 100
Paul Becotte Avatar answered Oct 06 '22 22:10

Paul Becotte