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?
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.
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.)
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.