In Docker, how can I exchange files between containers and then save them to an image?

I want to transfer data in a shared container volume to an image. I can't seem to do this? It seems to me that this is possible in Docker, but it seems to be completely contrary to the whole philosophy of not leaving data on the host, so part of me thinks that there should be a way to do this.

1. Terminal 1

Run the container in terminal 1 with the volume.

$ docker run -it -v /data ubuntu:14.10 /bin/bash root@19fead4f6a68 :/# echo "Hello Docker Volumes." > /data/foo.txt 

2. Terminal 2

Run the second container in Terminal 2, the file from container 1 is there, so that all dockers work.

 $ docker run -it --volumes-from 19fead4f6a68 ubuntu:14.10 /bin/bash root@5c7cdbfc67d8 :/# cat /data/foo.txt Hello Docker Volumes. 

3. Terminal 3

My understanding is that I can only capture the differences with the images, so I check what differences are on both containers. For some bizarre reason, my changes don't appear! ??

 $ docker diff 19fead4f6a68 A /data $ docker diff 5c7cdbfc67d8 A /data 

4. Back in terminal 1

I create a file outside the volume folder

 root@19fead4f6a68 :/# echo "Docker you are a very strange beast...." > /var/beast.txt 

5. Back to terminal 3

Now we have some changes that we can make, although I’m rather upset, because this is not data from the volume that I need to share with another container.

 $ docker diff 19fead4f6a68 A /data C /var A /var/beast.txt 

Clearly, this is by design. Does anyone have any ideas as to why docker doesn't allow me to save volume data into a commit? Is there any general exchange of files between containers, and then saving them to an image? I feel like something is missing me? Especially to the ends of the data exchange, avoiding connections between hosts.

+7
docker
source share
2 answers

Volumes are outside the container images. This is exactly what they are intended for - data output inside a container that is not in the image.

From Docker Docs :

A data volume is a specially designated directory in one or more containers that bypasses the Union file system to provide several useful functions for persistent or shared data:

  • Data volumes can be shared and reused between containers
  • Changes in the amount of data are made directly.
  • Changes to the data volume will not be included when updating the image.

If you want to save some changes as part of the image, make the changes inside the image, not the one. If you want to share changes in several containers, put this data in one, but you must create your own snapshots, rollbacks, etc., because Docker does not have this function.

You might be interested in Flocker .

+5
source share

It seems like there is a problem with adding volumes to docker:

https://github.com/docker/docker/issues/9382

+1
source share

All Articles