How to fix-Docker docker failed to compute cache key not found

The Docker failed to compute cache key error is result of docker buildcommand which is executed on a directory where the Dockefile is not present.

I had this issue when I was working with one of my project on my windows laptop and my directory structure looked like this -

1    \parent-directory  
2       -
3       - child-directory  (child directory with Dockerfile)
4           - DockerFile
5           -

If you look at the directory structure above then my Dockerfile is present under the child-directory.

How I was wrongly executing the docker build?

Considering the directory structure which I explained above my first mistake was I am on parent-directory and expecting to execute docker-build successfully but unfortunately the Dockerfile was present inside the child-directory.

Here is my wrong directory -

1    $ pwd
2    /home/rwagh/my-project/parent-directory

Here is the error which I got after running the docker-build command -

1    failed to compute cache key: "/parent-directory/child-directory/" not found: not found

How to fix error failed to compute cache key?

Now we know the issue and problem associated with the way we are executing the docker-build command.

So our aim is to execute the Dockerfile present under the child directory

  1. First switch to parent directory -
1   cd /home/rwagh/my-project/parent-directory
  1. Run the following docker-build command with explicit mention of Docker file present in the child directory
1  docker build -f child-directory\Dockerfile

So the above command will help you to fix the docker error failed to compute cache key. The only missing part was to specify the correct path of the Dockerfile present under the right directory.

Note: I had this issue while working with my docker project in Visual Studio and sometimes I feel visual studio make directory structure little fuzzy to work with, so it is always recommended to use the explicit docker-file path so that you do not end with this kind of issue.

Also look for missing directory which you mentioned in the Dockerfile

If the previous step does not help you to fix the issue then I would suggest to look at the logs carefully and go through the errors.

I also find one of the error which present inside my logs where it says missing

1  failed to compute cache key: "/child-directory/" not found: not found

so the problem which you can see over here is -

  1. Either it is missing the whole directory - /child-directory/
  2. Or you are missing file -

So make sure to check the files in your project directory.