Docker, Copying image, error - ERROR: failed to solve: failed to compute cache key: failed to calculate checksum

16.7k Views Asked by At

i'm doing a tutorial in docker, and trying to copy a image from docker, and reference the index.hmtl file im my local file, vinnyx05 -> is my login at docker, im running docker desktop. in using Windows 11. the code is:

PS C:\html> docker build -t vinnyx5/nginx-imersao13:latest . 
[+] Building 0.2s (6/6) FINISHED
 => [internal] load build definition from Dockerfile                                                                                         0.1s 
 => => transferring dockerfile: 101B                                                                                                         0.0s 
 => [internal] load .dockerignore                                                                                                            0.1s 
 => => transferring context: 2B                                                                                                              0.0s 
 => [internal] load metadata for docker.io/library/nginx:latest                                                                              0.0s 
 => [internal] load build context                                                                                                            0.0s 
 => => transferring context: 2B                                                                                                              0.0s 
 => CACHED [1/2] FROM docker.io/library/nginx:latest                                                                                         0.0s 
 => ERROR [2/2] COPY html/index.html /usr/share/nginx/html/                                                                                  0.0s 
------
 > [2/2] COPY html/index.html /usr/share/nginx/html/:
------
Dockerfile:3
--------------------
   1 |     FROM nginx:latest
   2 |
   3 | >>> COPY html/index.html /usr/share/nginx/html/
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref ccf5a995-3d05-4517-a1ee-20291664f134::ljszgt44a3wte8c2sal6f54p2: failed to walk /var/lib/docker/tmp/buildkit-mount2559770106/html: lstat /var/lib/docker/tmp/buildkit-mount2559770106/html: no such file or directory

i dont know how to fix this, help please? Thanks =)

im trying to do a copy of image, and edit de index.html locally

6

There are 6 best solutions below

0
On BEST ANSWER

Make sure you're running over a linux based terminal (like WSL). It seems to be a "windows" issue.

0
On

Docker cannot find the file html/index.html.

Probably, in relation to your folder structure, you should copy the file like this:

COPY ./html/index.html /usr/share/nginx/html
0
On

You are building from inside the html folder with:

PS C:\html> docker build -t vinnyx5/nginx-imersao13:latest . 

The build context in that command is . or the current directory.

You then attempt to copy the file html/index.html from that context to the image with:

COPY html/index.html /usr/share/nginx/html/

For that to work, the file C:\html\html\index.html needs to exist (note the double html in the path).

To fix this, either change your context to be a directory higher (not recommended since you are working just under c:\ and you don't want to copy the entire C drive to the docker temp directory which is frequently on the C drive). Or preferably fix the COPY command to reference a file that exists in your context, e.g.:

COPY index.html /usr/share/nginx/html/
0
On

Double check your .dockerignore file, if it exists make sure that the file mentioned in the error message is not present in this file.

0
On

Make sure you're using the right context folder when building image, especially in case of docker-compose.

0
On

I was on Linux when I got this error. I was building from a bash script located in a different directory. The solution was to ensure that when you invoke the docker build command, you are invoking it from the location of your Dockerfile.

Say the Dockerfile had an entry such as

COPY ./assets/file-to-copy ./

And a structure as follows

├── image-foo
│    ├── Dockerfile
│    └── assets
│         └──file-to-copy
└──build-script.sh

To build from the command line, make sure that you are in the image-foo directory.

cd image-foo
docker build -t foo .

Or if using a build script you do something like

build-script.sh

#!/bin/bash

# pre build stuff

cd ./image-foo
docker build -t foo .

# post build stuff