buildkit: Failed to compute cache key in newer version
This is a docker issue but it seems to be related to BuildKit only. this is something that was still working in docker ~19.03.10 but stopped functioning in 20.10.0+. I managed to bring down my DockerFile to a minimal repro:
This works (A.DockerFile):
FROM php:7.4.13-cli
COPY --from=composer:2.0.8 /usr/bin/composer /usr/local/bin/composer
This also works (B.DockerFile):
FROM php:7.4.13-cli
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/
This no longer works (C.DockerFile):
FROM php:7.4.13-cli
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/
COPY --from=composer:2.0.8 /usr/bin/composer /usr/local/bin/composer
Output from running A and C after eachother:
C:\Users\Test>set "DOCKER_BUILDKIT=1" & docker build -f A.Dockerfile .
[+] Building 3.6s (7/7) FINISHED
=> [internal] load build definition from A.Dockerfile 0.0s
=> => transferring dockerfile: 132B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/php:7.4.13-cli 2.9s
=> CACHED FROM docker.io/library/composer:2.0.8 0.0s
=> => resolve docker.io/library/composer:2.0.8 0.5s
=> CACHED [stage-0 1/2] FROM docker.io/library/php:7.4.13-cli@sha256:c099060944167d20100140434ee13b7c134bc53ae8c0a72e81b8f01c07a1f49d 0.0s
=> [stage-0 2/2] COPY --from=composer:2.0.8 /usr/bin/composer /usr/local/bin/composer 0.1s
=> exporting to image 0.1s
=> => exporting layers 0.0s
=> => writing image sha256:ea6d75bc9ad24e800c8083e9ea6b7774f2bd9610cb0e61b3640058c9c7fe34c6 0.0s
C:\Users\Test>set "DOCKER_BUILDKIT=1" & docker build -f C.Dockerfile .
[+] Building 1.0s (8/8) FINISHED
=> [internal] load build definition from C.Dockerfile 0.0s
=> => transferring dockerfile: 221B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/php:7.4.13-cli 0.2s
=> FROM docker.io/mlocati/php-extension-installer:latest 0.0s
=> => resolve docker.io/mlocati/php-extension-installer:latest 0.0s
=> => sha256:ccf3a05d8241580ad9d2a6c884a735bb248e90942ab23e0f8197f851a999ddac 526B / 526B 0.0s
=> CACHED FROM docker.io/library/composer:2.0.8 0.0s
=> [stage-0 1/3] FROM docker.io/library/php:7.4.13-cli@sha256:c099060944167d20100140434ee13b7c134bc53ae8c0a72e81b8f01c07a1f49d 0.0s
=> CACHED [stage-0 2/3] COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/ 0.0s
=> ERROR [stage-0 3/3] COPY --from=composer:2.0.8 /usr/bin/composer /usr/local/bin/composer 0.0s
------
> [stage-0 3/3] COPY --from=composer:2.0.8 /usr/bin/composer /usr/local/bin/composer:
------
failed to compute cache key: "/usr/bin/composer" not found: not found
This doesn’t happen consistently in my build, sometimes everything builds fine and there are no issues.
I’m using windows 10 (20H2) and the latest version of Docker Desktop that includes Docker version 20.10.2, build 2291f61, but I have also seen this happen on Linux with the same version
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 21
- Comments: 61 (5 by maintainers)
Make sure that the file that you are trying to copy is not part of the
.dockerignorefile.Disable buildkit works for me. Try
Docker Desktop on Mac v3.3.0 (62916), Engine: 20.10.5still has this issue. Only thing that helps is disabling Buildkit… This issue should be reopened, IMHO.Windows 20.10.5 users, here is how I fixed it:
daemon.json(should be inc:\Users\CURRENT_USER\.dockerfolder)."features": {"buildkit": false}. It should look something like:Cheers.
This flag helped me to get the real error and then I solved it from there when using
docker-compose. With the original error, I would not reach this fast to the cause of it. With flag (improved error):Without flag (original error):
On Windows, 20.10.5 and encountering this issue
I’m not sure if this fixes it for you: https://stackoverflow.com/a/66611529/554037
Try running:
In my case issue was file was in the
.dockerignore. Removing it from there workedAny update on this, it is happening on my 20.10.6 (OSX) version as well…
Docker Desktop on windows v.3.3.1 (63152), Engine 20.10.5 also still has this issue
I’m using version 20.10.5 of the Docker Engine on a Windows machine and I’m seeing this error using a very basic Dockerfile. Any updates?
when will this fix land in docker for mac?
@hanct probably because your base image (FROM …) of your Dockerfile is unix-based. And on unix systems back-slashes ( \ ) is not the norm. That is a fundamental difference between windows systems and unix systems. So just adapt your dockerfile so it can reach sub folders using regular slashes
You’re genius !
Agreed, I created https://github.com/moby/buildkit/issues/1647 (and somewhat related, https://github.com/moby/buildkit/issues/2130) for that.
This actually worked!
I had the following structure:
Running on Ubuntu 20.04LTS on WSL on Windows 10 (20H2), the following command got the build done
docker build -f docker/Dockerfile .. TheDockerfilecontained the following line, that was previously breaking the build:COPY persistence/changelogs/ /liquibase/changelogs/. Executing the command above from the root directory (in my example above) worked.In my case it “failed to walk” because I was copying resources from outside the root folder (where we build the Dockerfile). Solved it by contextualizing the parent folder of the root inside docker-compose.yml:
Saw this issue using WSL2 on Windows. Disabling buildkit seemed to fix the issue.
Encountered the:
error today on MacOS 10.15.7 and Docker Desktop 3.3.1. I believe I figured out why my
buildcommand was failing; the following might only be tangentially related to the topic.The
Dockerfilefor the parent image looks something like:with the following
buildcommand:and the
Dockerfilefor the image I was attempting to build only contains aFROMinstruction. i.e.Following best practices, I ran the following
buildcommand for the child image:Running a slightly different
buildcommand fixed the issue:Note the difference between build contexts and the addition of the
--fileflag.I believe the
buildfailed when the current dir. was withheld from the build context, but then why did thebuildfail at the:instruction and not the:
instruction?
Should also note here that the error was consistent and
pruningeverything and restarting the Docker daemon didn’t change anything; BuildKit is enabled.@thaJeztah I see this issue is closed but many people are still expiriencing the issue. It is because the fix is not rolled out yet, or is it because the problem is still not solved?
Expiriencing the same thing, any update?