-
Notifications
You must be signed in to change notification settings - Fork 501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Race condition when using cache-mounts with multi-arch builds. #549
Comments
You can't use variables in |
@tonistiigi I take it then that it's impossible to use a |
The simplest is to put your cache in a subdir of the mount so it doesn't collide. Another way is to use |
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
...
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
echo "[+] Installing APT base system dependencies for $TARGETPLATFORM..." \
&& apt-get update -qq \
&& apt-get install -qq -y --no-install-recommends \
apt-transport-https ca-certificates apt-utils gnupg2 curl wget \
...
&& rm -rf /var/lib/apt/lists/*
More info here: moby/buildkit#1673 With these changes I achieved a >20x speed gain when rebuilding a frequently changed complex docker image with lots of apt lines. |
@pirate If you are using this pattern for multi-platform then add |
Cool! Just noticed they merged support for variables in mount arguments: moby/buildkit#815 So the updated version would look like this? I added the ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
...
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
...
RUN --mount=type=cache,id=apt-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/var/cache/apt \
&& apt-get update -qq \
&& apt-get install -qq -y --no-install-recommends \
apt-transport-https ca-certificates apt-utils gnupg2 curl wget ... \
&& rm -rf /var/lib/apt/lists/* Edit: confirmed this works 👍 (build speeds are now 20x faster for small changes) and is now how we do it in ArchiveBox's Dockerfile |
@pirate In your latest example you are using |
Yes, following @tonistiigi's comment the additional cache keys allow us to go back to using |
@pirate If you put the |
Issue
I've encountered intermittent failures using
--mount=type=cache
to shareapk
package manager cache when doing multi-platform builds usingbuildx
with thedocker-container
driver. It appearsbuildx
attempts to use the same cache even though they have different identifiers resulting in a failure for the package manager as it expects the files in the cached folder to be platform specific. This is intermittent though there are times where inbuildx
correctly creates two separate caches and the build is successful.System Info
Steps to reproduce.
Setup the builder:
Enable multi-arch builds via Qemu:
Attempt to build:
See the error in the logs in which
apk
cannot be shared across architectures.Note the outputs of
ls -lah /var/cache/apk
differs asamd64
wrote to the directory beforearm64
read from it.The text was updated successfully, but these errors were encountered: