简体   繁体   中英

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.

All docker build work in the way, that you describe.

The only thing need to be taken into account is layer dependencies.

Consider Dockerfile

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 cmd1
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

FROM myimage

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 commit :

https://docs.docker.com/engine/reference/commandline/commit/

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM