moby / moby/buildkit

Multi-Stage build with --mount=type=cache and COPY from mount-cache location in next stage?

Open
#3,936 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
10.3k
Forks
1.5k
Avg merge
1d 23h
Merged PRs (30d)
48

Description

I'm trying to optimize my multi-stage build by using RUN --mount=type=cache,id=xx,target=/zz. I need to re-use the cached location in my next build-stage that will finalize the build. It came in my mind, that I could use something like COPY --mount=type=cache,id=xx /zz but obviously as far as I consulted the buildkit-reference --mount=type=cache statements are only supported for RUN, but not for COPY.

Are there any plans to realize that? As far as I see (in theorie) the only workaround would be something like this:

FROM ... AS stage-1
RUN \
  --mount=type=cache,id=xx,target=/usr/lib/foo \
  do-some-build

FROM final-distro AS stage-2
RUN \
  --mount=type=cache,id=xx,target=/build/usr/lib/foo \
  cp -rf /build/usr/lib/foo /usr/lib/foo

Or is there any smarter solution?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the BuildKit reference for RUN --mount=type=cache and the existing multi-stage behavior described in the issue. Define the intended semantics for exposing a cache mount to a later stage, then assess the two-stage example; the work is done when the behavior is specified and supported consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, dockerfile
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.