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

6

10

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

Morpho answered 14/6, 2023 at 13:21 Comment(2)
pls, post the DockerfilePeachy
FROM nginx:latest COPY index.html /usr/share/nginx/html/Morpho
P
2

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

Peachy answered 14/6, 2023 at 13:59 Comment(0)
P
9

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

Psychopharmacology answered 8/1, 2024 at 8:2 Comment(0)
P
2

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

Peachy answered 14/6, 2023 at 13:59 Comment(0)
H
1

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
Hibernate answered 14/6, 2023 at 13:42 Comment(0)
M
1

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/
Momentum answered 14/6, 2023 at 14:5 Comment(0)
E
1

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

Ecclesiastic answered 31/1, 2024 at 3:25 Comment(0)
Y
1

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
Yaakov answered 22/2, 2024 at 9:47 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.