linuxdockerparent-childpropagationimage-file

Propgate changes from base image to "child" image, Docker


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.


Solution

  • 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.