Rebuild same docker image with only the additional changes in the Dockerfile
I build an docker image using a Dockerfile. After building the image, I made some basic changes on the Dockerfile. Is it possible to rebuild the same image with just the additional changes. Since, it takes very long time to create the image, I don’t want to build it completely. Thanks in advance.
3 Solutions collect form web for “Rebuild same docker image with only the additional changes in the Dockerfile”
All docker build work in the way, that you describe.
The only thing need to be taken into account is layer dependencies.
FROM something RUN cmd1 RUN cmd2 RUN cmd3 RUN cmd4
If you change
cmd1 then all layers will be rebuilt, because they could be different with respect to
If you change
cmd4 than only this command will be rebuilt, because it has not affect any other layers.
Think about what commands need to be run in what order – maybe you can improve it by reordering the statements.
Yes, if you tag your docker image myimage, just start your other Dockerfile with
and put after this your additional changes
You can’t rebuild it with the changes, you would need to store persistent data on a volume for that.
To save your changes,however, you can use
Create a new image from a container’s changes
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
It can be useful to commit a container’s file changes or settings into
a new image. This allows you debug a container by running an
interactive shell, or to export a working dataset to another server.
Generally, it is better to use Dockerfiles to manage your images in a
documented and maintainable way. Read more about valid image names and
The commit operation will not include any data contained in volumes
mounted inside the container.
By default, the container being committed and its processes will be
paused while the image is committed. This reduces the likelihood of
encountering data corruption during the process of creating the