Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Any way to auto-detect modified lines in Dockerfile and only rebuild from the first modified line onwards?

I’m building a docker image using a Dockerfile, and I often have to tweak lines further down the Dockerfile. When I instruct docker to rebuild the image, it starts from the very top of the Dockerfile (installing dependencies, etc.), and works down to the actual changed lines. Is there any technology or general method to detect what the first modified line in a Dockerfile is, and to only rebuild from that point onwards?

This request is based on an assumption that a snapshot can be stored at each line in a Dockerfile. I assume this is possible because the output logs while building indicate that intermediate containers are being created at each line break.

I’ve tried running containers at each of the breakpoint image IDs, and it is indeed possible to look at containers running from each breakpoint (e.g. before and after installing packages, before and after pulling in a data file from a URL, etc.) But I don’t know how to instruct docker to rebuild from one of these intermediate image points? Furthermore, I don’t know how to list these intermediate points after an image’s final form has been built.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Usually docker does this automatically. If you don’t change anything in the beginning of the Dockerfile it should just cache the intermediate layers. You can see this in the output through these lines: ---> Using cache
More information on build caching can be found here.

If you are building on an CI/CD system or any other system, where the previous build cache is not available, you can externalize the cache through cache backends.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading