Docker Community Forums

Share and learn in the Docker community.

Multi-stage copy of everything in an image fails after version 2.4.0.0 (earlier versions work)

I have an example docker build - a Dockerfile that looks like the following:

FROM debian:buster-slim as other
FROM alpine:latest
COPY --from=other / /

This builds successfully prior to the 2.4.0.0 version of docker desktop for windows. Attempting to build with any version 2.4.0.0 and newer results in the following style of copy error:

 => ERROR [stage-1 2/2] COPY --from=other / /                                                                      1.0s
------
 > [stage-1 2/2] COPY --from=other / /:
------
failed to solve with frontend dockerfile.v0: failed to build LLB: cannot replace to directory /var/lib/docker/overlay2/hc1w3xu51id4vm10bbsijznxa/merged/var/lock with file

Does anyone know of a work-around for this style of whole image copy over an existing image to work in docker desktop for Windows versions 2.4.0.0+?

Note also the above is just a useless example to illustrate the issue with small images - I have a real scenario where I am copying an entire distroless image right over the top of the equivalent distro’d image in order to restore package managers where this whole image copy is useful.

Any help is much appreciated.

Go to settings, then Docker Engine and change “buildkit: true” to “buildkit: false”. Buildkit is a useful feature but there are some things you cannot the with it. I don’t know if it is intentional in this case but disabling buildkit solved it for me.

If you don’t want to disable it globally, then you can disable it in powershell temporarily

$env:DOCKER_BUILDKIT=0
docker build ...
1 Like

Thank you very much @rimelek - yes, disabling build-kit worked like a charm!