We are using a shared image the cache mount in the dockerfile: ONBUILD RUN --mount=type=cache,target=/var/lib/apt/lists,sharing=locked \ apt update ... This image is then used as the root image in another dockerfile. When this second docker image is build, it fails because of: failed to solve: cannot mount from stage "scratch" to "/var/lib/apt/lists", stage needs to be defined before current command A work around was found by defining FROM scratch as scratch and FROM parent as parent in the child docker image, but this is cumbersome. The build should work just like it does locally.