Search code examples
lxcdocker

Is it possible to allow the containers running on the same image to share their filesystem?


I am going to explain the question with an example. Suppose that we are running two seperate processes on the same image. One of them creates a file and continues to execute. I need the other process running in a different container to see, inspect, change this file.

Thanks in advance.


Solution

  • You can use the volumes. The idea is for the container A to create a volume mounted in a specific directory, to perform all operation that are needed to be shared there and for the container B to mount the volume from the container A.

    1) ID=$(docker run -d -v /tmp base /bin/sh -c 'echo hello > /tmp/world')

    2) docker run -volumes-from $ID base cat /tmp/world

    Notice that there is no commit. Both container use the same image.