8

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 ?

Mohamed AL ANI
  • 2,012
  • 1
  • 12
  • 29
user6403833
  • 269
  • 5
  • 13

1 Answers1

5

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

Paul Becotte
  • 9,767
  • 3
  • 34
  • 42