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

StackOverflow https://stackoverflow.com/questions/17011008

  •  31-05-2022
  •  | 
  •  

Question

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.

Was it helpful?

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top