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.
2 Solutions collect form web for “Is it possible to allow the containers running on the same image to share their filesystem?”
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.
ID=$(docker run -d -v /tmp base /bin/sh -c 'echo hello > /tmp/world')
docker run -volumes-from $ID base cat /tmp/world
Notice that there is no commit. Both container use the same image.
Mounting host directories into a container is now possible with the new Bind Mounts feature (currently in master and set to be released shortly with 0.5.0).
Usage is as follows:
docker run -t -i -v /host:/container base bash
This will ensure that the host’s
/host directory is mounted to the container’s
/container directory, with read-write access.