Hi Team - We are trying to build a docker image and this is a Multistage build.
docker build is erroring out with the below message
failed to compute cache key: failed to walk /opt/data/docker/data/tmp/buildkit-mount2977242485/usr/lib/.build-id/01/e11c545160c74b88b9ce9259e7467863eab9e7: lstat /opt/data/docker/data/tmp/buildkit-mount2977242485/usr/lib/.build-id/01/e11c545160c74b88b9ce9259e7467863eab9e7: no such file or directory
I can’t find it in the documentation, but the example in the docs is using absolute path and I have never tried to copy from another stage without absolute path as a source. Never even thought of doing it so I agree with @meyay, that is a very likely cause of the error message.
I forgot to mention why The motivation is to get debug information, so you can see the current location as absolute path and in which subfolder the folders you try to copy are.
Of course, once you identified how the absolute paths need to look like, you can remove the RUN instruction again.
I removed the second stage in my Dockerfile and built the image…I see the folders that I am trying to copy in the second stage are available on the container filesystem under /
drwxr-xr-x. 2 root root 6 Jan 26 11:33 snapshot-dependencies
drwxr-xr-x. 3 root root 16 Jan 26 11:33 spring-boot-loader
drwxr-xr-x. 4 root root 36 Jan 26 11:33 application
drwxr-xr-x. 3 root root 21 Jan 26 11:33 dependencies
[root@5917b498bdfe /]# pwd
/
#9 [stage-1 3/5] COPY --from=builder snapshot-dependencies/ / #9 sha256:576ab9b6d9a000b79634f5e01b190f2dfe6ec9836fcc8c2be70dd69e34d1e571 #9 ERROR: failed to walk /opt/data/docker/data/tmp/buildkit-mount4132688350/usr/lib/.build-id/01/e11c545160c74b88b9ce9259e7467863eab9e7: lstat /opt/data/docker/data/tmp/buildkit-mount4132688350/usr/lib/.build-id/01/e11c545160c74b88b9ce9259e7467863eab9e7: no such file or directory
#8 [stage-1 2/5] COPY --from=builder dependencies/ / #8 sha256:efe19f075625e924493bbec32599cb5eecda4227631d78004b9352975f2aa728 #8 ERROR: failed to walk /opt/data/docker/data/tmp/buildkit-mount4136272112/usr/lib/.build-id/01/e11c545160c74b88b9ce9259e7467863eab9e7: lstat /opt/data/docker/data/tmp/buildkit-mount4136272112/usr/lib/.build-id/01/e11c545160c74b88b9ce9259e7467863eab9e7: no such file or directory
I have a similar problem when doing a multi-stage build on Ubuntu on WSL2 on Windows 11 with Docker Desktop.
My Dockerfile
FROM node:latest as builder
WORKDIR /usr/src/app
COPY . .
RUN npm install
RUN npm run build
RUN cp -r /usr/src/app/.output/ /output/
FROM node:latest
WORKDIR /usr/src/app
COPY --from=builder /ouput/nitro.json .
I open Ubuntu, then docker build to stage ‘builder’ and start a container from that image manually in the Windows interface of Docker Desktop. I have confirmed that the build-image contains the file /output/nitro.json.
Then I do a docker build for the whole file. Still COPY --from=builder /ouput/nitro.json . gives the following error
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref c290b074-c322-479c-b461-44419293caef::te2yh1nks699h0puaas9890vq: failed to walk /var/lib/docker/tmp/buildkit-mount2099609999/ouput: lstat /var/lib/docker/tmp/buildkit-mount2099609999/ouput: no such file or directory
It seems like the COPY --from command tries to pull the files from a folder that does not exist in the Ubuntu-context.