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)

Most upvoted comments

Make sure that the file that you are trying to copy is not part of the .dockerignore file.

Disable buildkit works for me. Try

DOCKER_BUILDKIT=0 docker build ...

Docker Desktop on Mac v3.3.0 (62916), Engine: 20.10.5 still 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:

  1. Locate daemon.json (should be in c:\Users\CURRENT_USER\.docker folder).
  2. Add the following property: "features": {"buildkit": false}. It should look something like:
{
  "registry-mirrors": [],
  "insecure-registries": [],
  "debug": true,
  "experimental": false,
  "features": {"buildkit": false}
}

Cheers.

Disable buildkit works for me. Try

DOCKER_BUILDKIT=0 docker build ...

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):

COPY ../../../server/src/test/resources/elasticsearch/agents/agents_mapping.json /tmp/agents_mapping.json
COPY failed: forbidden path outside the build context: ../../../server/src/test/resources/elasticsearch/agents/agents_mapping.json ()

Without flag (original error):

COPY ../../../server/src/test/resources/elasticsearch/agents/agents_mapping.json /tmp/agents_mapping.json:
failed to compute cache key: "/server/src/test/resources/elasticsearch/agents/agents_mapping.json" not found: not found

On Windows, 20.10.5 and encountering this issue image

I’m not sure if this fixes it for you: https://stackoverflow.com/a/66611529/554037

Try running:

docker build -f PROJECT_DIR\Dockerfile .

In my case issue was file was in the .dockerignore. Removing it from there worked

Any 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?

After lot of struggling, able to get it work. Not because of .dockerignore (i don’t have this file), but cos of the slash

Not working docker image build --build-arg JAR_FILE=“build\libs\licensing-service-0.0.1-SNAPSHOT.jar” . docker image build --build-arg JAR_FILE=“build\libs\licensing-service-0.0.1-SNAPSHOT.jar” .

Working docker image build --build-arg JAR_FILE=“build/libs/licensing-service-0.0.1-SNAPSHOT.jar” .

Do note that my host machine is windows, 10 pro.

Why would / works, and not \ , until now its still a mystery to me.

@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

Make sure that the file that you are trying to copy is not part of the .dockerignore file.

You’re genius !

it seems like the error message is much clearer about this when DOCKER_BUILDKIT=0; arguably this is a (minor) regression in buildkit.

Agreed, I created https://github.com/moby/buildkit/issues/1647 (and somewhat related, https://github.com/moby/buildkit/issues/2130) for that.

I’m not sure if this fixes it for you: https://stackoverflow.com/a/66611529/554037

Try running:

docker build -f PROJECT_DIR\Dockerfile .

This actually worked!

I had the following structure:

| | - persistence | --> changelogs | - docker | --> Dockerfile

Running on Ubuntu 20.04LTS on WSL on Windows 10 (20H2), the following command got the build done docker build -f docker/Dockerfile .. The Dockerfile contained 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:

        build:
            context: ../

Saw this issue using WSL2 on Windows. Disabling buildkit seemed to fix the issue.

Encountered the:

failed to compute cache key: “. . .” not found: not found

error today on MacOS 10.15.7 and Docker Desktop 3.3.1. I believe I figured out why my build command was failing; the following might only be tangentially related to the topic.

The Dockerfile for the parent image looks something like:

FROM node:erbium-alpine

# . . .

ONBUILD COPY ["internals/.", "./internals/"]

ONBUILD COPY ["app/.", "./app/"]

# . . .

with the following build command:

docker build \
--no-cache \
--progress=plain \
--tag parentimage:sometag \
- < Dockerfile.parent

and the Dockerfile for the image I was attempting to build only contains a FROM instruction. i.e.

FROM parentimage:sometag

Following best practices, I ran the following build command for the child image:

docker build \
--build-arg GIT_COMMIT=$(git rev-parse HEAD) \
--no-cache \
--progress=plain \
--secret id=dotenv,src=.env \
--secret id=npmrc,src=.npmrc \
--tag someimage:sometag \
- < Dockerfile.child

#=>

#1 [internal] load build definition from Dockerfile.child
. . .
------
 > [4/1] COPY [internals/., ./internals/]:
------
------
 > [5/1] COPY [app/., ./app/]:
------
failed to compute cache key: "/app" not found: not found

Running a slightly different build command fixed the issue:

docker build \
--build-arg GIT_COMMIT=$(git rev-parse HEAD) \
--file Dockerfile.child \
--no-cache \
--progress=plain \
--secret id=dotenv,src=.env \
--secret id=npmrc,src=.npmrc \
--tag someimage:sometag \
.

Note the difference between build contexts and the addition of the --file flag.

I believe the build failed when the current dir. was withheld from the build context, but then why did the build fail at the:

COPY ["app/.", "./app/"]

instruction and not the:

COPY ["internals/.", "./internals/"]

instruction?

Should also note here that the error was consistent and pruning everything 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?