I'm building a docker image that does a lot of apt-get installs
and when one fails the container build errors and after fixing the Dockerfile docker build -t tag .
will still download dependencies that were successfully installed in the first build. How can I make docker build
to continue where it left off?
Asked
Active
Viewed 260 times
3

Stylishcoder
- 1,142
- 1
- 11
- 21
2 Answers
0
One option to consider is using separate Dockerfiles. Then you can simply use the --cache-from
flag, per the documentation, to use the base image as cache.

oxr463
- 1,573
- 3
- 14
- 34
0
Docker will run whole RUN
commands, and caching is at that level. Usually it's beneficial to have just one RUN apt-get install
line, but there's nothing actually wrong with breaking it up
FROM ubuntu:18.04
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install package1 package2 package3
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install package4 package5 package6
Then if something fails downloading package5
, re-running the docker build
will start after the cached layer with the first three packages installed.
(If you're installing so many packages that this is routinely a problem, also consider whether you can reduce the scope of your container to something smaller that needs fewer initial downloads.)

David Maze
- 130,717
- 29
- 175
- 215
-
Which command do I use to have docker use this cache because at the moment it doesn't. If the 9nth package fails to download and the build fails. A rerun still downloads the 8 packages that were already downloaded before. I'm installing dependencies for an open source software I want to work on so I can't split it into different containers. And I do have just RUN command but it's trying to install multiple packages. – Stylishcoder Aug 08 '19 at 05:15