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 - test-file-1.py
3 - child-directory (child directory with Dockerfile)
4 - DockerFile
5 - test-file-2.py
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/test-file-2.py" 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
- First switch to parent directory -
1 cd /home/rwagh/my-project/parent-directory
- 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 test-file-2.py
1 failed to compute cache key: "/child-directory/test-file-2.py" not found: not found
so the problem which you can see over here is -
- Either it is missing the whole directory - /child-directory/test-file-2.py
- Or you are missing file - test-file-2.py
So make sure to check the files in your project directory.
Posts in this Series
- (docker run -d) Why Does a Docker Container Stop Automatically?
- Attach and detach from Docker's process?
- How I Change Name of My Docker Repository and Rename Images?
- How to set-up Cron Jobs in Docker Containers?
- 4 Ways to copy file from localhost to docker container
- Multiple commands execution in Docker Compose?
- How to push Docker Images to AWS ECR(Elastic Container registry)?
- How to Copy Docker images from one host to another host?
- What is persistent storage in docker and how to manage it
- Docker Installation on MacOS, Linux and Windows
- Docker - ADD, Update, Export Environment variable
- How to fix-Docker docker failed to compute cache key not found
- How to fix docker driver failed programming external connectivity on endpoint webserver?
- How to fix docker error executable file not found in $PATH?
- How to expose port on live containers?
- How to expose multiple ports with Docker?
- How to restart single docker container within multiple docker container?
- How to edit file within Docker container or edit a file after I shell into a Docker container?
- How to fix Error starting docker service Unit not found?
- How to remove old, unused images of Docker?
- How to fix docker error invalid reference format error?
- How to fix requested access to the resource is denied?
- How to fix Docker error cannot delete docker container conflict unable to remove repository reference?
- How to fix docker error no space left on device?
- How to connect localhost from docker container?
- Docker COPY vs Docker ADD?
- 6 Ways to fix - Got permission denied while trying to connect to the Docker daemon socket?
- 6 Ways to fix – Docker COPY failed: stat no source files were specified