We're building Docker images in our CI, but we can't get docker buildx build to utilise a pulled image as a cache.
Here are the docker commands that are executed:
docker pull "ghcr.io/foo/bar/baz"
docker buildx build . --tag "ghcr.io/foo/bar/baz"
docker push "ghcr.io/foo/bar/baz"
How can we modify docker buildx build to use the pulled image as a cache, ensuring that not every RUN is executed if the command remains unchanged?
Here's our Dockerfile:
FROM amd64/alpine:3.16 as build0
RUN apk update && apk add autoconf bash [...]
FROM build0 as build1
RUN mkdir /tmp/build-deps && cd /tmp/build-deps && [...]
FROM build1 as build2
RUN cd /tmp/build-deps && wget ${patch_uri} && [...]
FROM build2 as build3
RUN mkdir /root/build-deps && [...]
FROM build3 as build4
RUN cd /tmp/build-deps/ && mkdir php-ext && cd php-ext && [...]
Use the
--cache-fromoption when building withdocker buildxBy specifying this option, Docker will re-use layers from the pulled image where the initial steps have not changed in the Dockerfile and the layers are the same.