Continue building Docker image after error occured

Viewed 1754

I have a Dockerfile that install Ubuntu and some packages over it and then proceeds to use these packages. Let's say I need to run 'wget' command, but forgot to issue install of the 'wget' package. I add the package to install command and continue with my execution. However I have to start over - install Ubuntu, install package, etc., or do I? Is there ability to save what I did until error occurred and continue from that point after I did my fixes instead of downloading everything again?

2 Answers

Sometimes for this instance you might want to subdivide your build into a chain of images. Each successive step picks up the previous step at the FROM command.

Just to point out that David Maze's answer was most appropriate for my case:

Any time anything changes, none of the later steps will be cached. Since you have COPY . /camera very early in the Dockerfile, the following RUN apt-get ... becomes non-cacheable if anything changes at all in your source tree. I'd move that to later.

This is what I had COPY command in a wrong place, which really makes sense - I copy everything docker accumulated before resolving what I needed so I ended executing all directives after COPY every time I build the image. After I moved COPY down as David suggested, all the cached data was there.

Related