0

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.

sarslanhan
  • 517
  • 2
  • 7
  • 13

2 Answers2

2

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.

creack
  • 116,210
  • 12
  • 97
  • 73
  • Thanks, this will probably solve the problem that i asked. Now, i have two more questions, is it possible to mount a folder from the host operating system? If it is, please ignore the rest. If not, i am thinking of using the remote api to create the container that hosts the shared volume. However as far as i understand, '/containers/create' endpoint has a parameter 'Volumes' and its type is a little unclear. String and json object of the form (string->string) did not worked for me. Do you have any suggestions for this issue? – sarslanhan Jun 09 '13 at 18:05
  • The 'Volumes' paremeter takes an array of string, not an object. Mounting volumes from the host is not yet possible but will be soon. (Next week I think). – creack Jun 09 '13 at 19:04
2

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.

gabrtv
  • 3,558
  • 2
  • 23
  • 28
  • It seems the -b option been renamed to -v in the meantime: [https://github.com/dotcloud/docker/pull/602#issuecomment-19944402] – caiman Sep 18 '13 at 15:51