1

I am using docker and I was wondering if it was possible to propogate changes to "child" images of a base image. The following sequence of actions should hopefully give a more clear picture as to what I mean.

docker run -i -t baseimage               // start up baseimage

<detach while leaving baseimage running>

docker commit <baseimage id> childimage  // new image created from baseimage

docker run -i -t baseimage               // start up baseimage

touch test.txt                           // make some small change

<detach while leaving baseimage running>

docker commit <baseimage id> baseimage   // save base image

docker run -i -t childimage              // start up childimage

ls test.text                             // test.txt isn't there

The reason I want to do this is that I had a base image that I created several child images from. Only after I had created the child images did I realize that I needed java to be installed across all of them. It would be much easier for me to somehow install java to the base image and have it be propagated to the "children", rather than go through each child image and install java.

I admit I am new to docker, so is such a thing possible? If not, how would you go about modifying several images with the same change in one go? Is that possible? Thanks.

Zack
  • 13,454
  • 24
  • 75
  • 113
  • When you design your docker inheritance hierarchy, there is no need for propagating anything manually as children automatically get anything of their parent docker file on instantiation. – Smutje Jul 28 '15 at 20:30
  • this is not the case. A container made from a child image did not inherit the test.txt file from the base image – Zack Jul 28 '15 at 20:32
  • Yes, because you did not read my first sentence "When you design your docker inheritance hierarchy" - using Dockerfile. – Smutje Jul 29 '15 at 05:15
  • Even if you build your images based on Dockerfile, you will still need to re-build child images before changes made in parent would be taken into account. – luka5z Aug 29 '16 at 14:52

2 Answers2

3

Running docker containers relate to the images they are created from in an "instance of" type of way. Meaning you cannot "propagate" the change in the way to intend. You are much better off using a Dockerfile to describe how to build your docker images, instead of manually modifying running containers.

Noni Peri
  • 131
  • 2
1

No.

Containers are ephemeral, you throw them away and start again rather than try to patch them up.

Instead, use a Dockerfile to create an image for your containers. When you want to make a change, update the Dockerfile and replace the old container with a new version.

Adrian Mouat
  • 44,585
  • 16
  • 110
  • 102