Cache mounts without persisting cache folder in Docker image #3746
Unanswered
ralbertazzi
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there 👋 I started playing with cache mounts (
RUN --mount=type=cache
) but something that I'm failing to understand is how/if it's possible to avoid persisting the cache folder in the final image. Let's take an example from the buildkit reference:RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ --mount=type=cache,target=/var/lib/apt,sharing=locked \ apt update && apt-get --no-install-recommends install -y gcc
How can I exploit the caching functionalities without having
/var/cache/apt
and/var/lib/apt
in my final image? I guess one solution could be using multi-stage builds (use cache mounts in first stage, copy artifacts in second stage) but I'm wondering if this is always possible - for instance if you want to install some apt packages in the final stage I guess you'd have to leave with the cache being there.Am I missing some other workaround?
Beta Was this translation helpful? Give feedback.
All reactions