Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker : failed to compute cache key

I am trying to build a docker image for my sample-go app. I am running it from the sample-app folder itself and using the goland editor's terminal. But the build is failing and giving me certain errors.

My docker file looks like this:

FROM alpine:latest

RUN mkdir -p /src/build
WORKDIR /src/build

RUN apk add --no-cache tzdata ca-certificates

COPY ./configs /configs
COPY main /main

EXPOSE 8000

CMD ["/main"]

command for building:

docker build --no-cache --progress=plain  - < Dockerfile

Error And Logs:

#1 [internal] load build definition from Dockerfile
#1 sha256:8bb9ee83603259cf748d90ce42602f12527fa720d7417da22799b2ad4e503497
#1 transferring dockerfile: 222B done
#1 DONE 0.0s

#2 [internal] load .dockerignore
#2 sha256:f93d938488588cd0e0a94d9d343fe69dcfd28d0cb1da95ad7aab00aac50235c3
#2 transferring context: 2B done
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/library/alpine:latest
#3 sha256:13549c58a76bcb5dac9d52bc368a8fb6b5cf7659f94e3fa6294917b85546978d
#3 DONE 0.0s

#10 [1/6] FROM docker.io/library/alpine:latest
#10 sha256:d20daa00e252bfb345a1b4f53b6bb332aafe702d8de5e583a76fcd09ba7ea1c1
#10 CACHED

#7 [internal] load build context
#7 sha256:0f7a8a6082a837c139acc2855e1b745bba9f28cc96709d45cd0b7be42442c0e8
#7 transferring context: 2B done
#7 DONE 0.0s

#4 [2/6] RUN mkdir -p /src/build
#4 sha256:b9fa3007a44471d47414dd29b3ff07ead6af28ede820a2b4bae0ce84cf2c5a83
#4 CACHED

#5 [3/6] WORKDIR /src/build
#5 sha256:b2ec58a365fdd74c4f9030b0caff2e2225eea33617da306678ad037fce675388
#5 CACHED

#6 [4/6] RUN apk add --no-cache tzdata ca-certificates
#6 sha256:0966097abf956d5781bc2330d49cf715cd52c3807e8fedfff07dec50907ff03b
#6 CACHED

#9 [6/6] COPY main /main
#9 sha256:f4b81960427c014a020361bea0903728f289e1d796892fe0adc6409434f3ca76
#9 ERROR: "/main" not found: not found

#8 [5/6] COPY ./configs /configs
#8 sha256:630f272dd60dd307f40dbbdaef277ee0dfc24b71fa11e10a3b8efd64d3c05086
#8 ERROR: "/configs" not found: not found

#4 [2/6] RUN mkdir -p /src/build
#4 sha256:b9fa3007a44471d47414dd29b3ff07ead6af28ede820a2b4bae0ce84cf2c5a83
#4 DONE 0.2s
------
 > [5/6] COPY ./configs /configs:
------
------
 > [6/6] COPY main /main:
------
failed to compute cache key: "/main" not found: not found

PS: I am not able to find where is the problem? Help Please

like image 800
Umang Mundhra Avatar asked Apr 01 '26 10:04

Umang Mundhra


2 Answers

In my case I missed the folder entry in .dockerignore file. Do something like that.

**/*
!docker-images
!configs
!main
like image 182
Dheeraj kumar Rao Avatar answered Apr 03 '26 22:04

Dheeraj kumar Rao


This is a basic mistake.

  • COPY ./configs /configs: copy the folder configs from the host to the Docker image.
  • COPY main /main: copy the executable file main from the host to the Docker image.

The problems are:

  • The base Docker images do not have these folders /configs, /main. You must create them manually (Docker understood your command this way).
  • But I have some advice:
    • Create 2 Docker images for 2 purposes: build, production.
    • Copy the source code into Docker builder image which is use for building your app.
    • Copy necessary output files from the Docker builder image into the Docker production image.
like image 23
ansidev Avatar answered Apr 03 '26 23:04

ansidev