kubernetes-up-and-running / kuard

Demo app for Kubernetes Up and Running book
Apache License 2.0
1.56k stars 535 forks source link

Getting an error `/go/bin/kuard` in chapter 2 Multistage image builds #45

Closed singhprincejeet closed 2 years ago

singhprincejeet commented 2 years ago

I am using a Macbook air with M1 chip. I cloned the git repo and tried building it using the docker command docker build . -t kuard. I got the following error:

 => ERROR [stage-1 2/2] COPY --from=build /go/bin/kuard /kuard                                                                                                                                                                                                                      0.0s
------
 > [stage-1 2/2] COPY --from=build /go/bin/kuard /kuard:
------
failed to compute cache key: "/go/bin/kuard" not found: not found
Full logs ``` ➜ kuard git:(master) docker build . -t kuard [+] Building 1.4s (16/16) FINISHED => [internal] load build definition from Dockerfile 0.1s => => transferring dockerfile: 37B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 34B 0.0s => [internal] load metadata for docker.io/library/alpine:latest 1.0s => [internal] load metadata for docker.io/library/golang:1.12-alpine 1.1s => [auth] library/golang:pull token for registry-1.docker.io 0.0s => [auth] library/alpine:pull token for registry-1.docker.io 0.0s => [internal] load build context 0.1s => => transferring context: 6.05kB 0.1s => [build 1/7] FROM docker.io/library/golang:1.12-alpine@sha256:3f8e3ad3e7c128d29ac3004ac8314967c5ddbfa5bfa7caa59b0de493fc01686a 0.0s => CACHED [stage-1 1/2] FROM docker.io/library/alpine@sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300 0.0s => CACHED [build 2/7] RUN apk update && apk upgrade && apk add --no-cache git nodejs bash npm 0.0s => CACHED [build 3/7] RUN go get -u github.com/jteeuwen/go-bindata/... 0.0s => CACHED [build 4/7] WORKDIR /go/src/github.com/kubernetes-up-and-running/kuard 0.0s => CACHED [build 5/7] COPY . . 0.0s => CACHED [build 6/7] RUN dos2unix build/build.sh 0.0s => CACHED [build 7/7] RUN build/build.sh 0.0s => ERROR [stage-1 2/2] COPY --from=build /go/bin/kuard /kuard 0.0s ------ > [stage-1 2/2] COPY --from=build /go/bin/kuard /kuard: ------ failed to compute cache key: "/go/bin/kuard" not found: not found ```

I tried building using amd64 platform but still got the same error. Command I ran: docker buildx build --platform linux/amd64,linux/arm64 . The error I got:

 => CANCELED [linux/amd64 build 7/7] RUN build/build.sh                                                                                                                                                                                                                            50.9s
 => ERROR [linux/arm64 stage-1 2/2] COPY --from=build /go/bin/kuard /kuard                                                                                                                                                                                                          0.0s
------
 > [linux/arm64 stage-1 2/2] COPY --from=build /go/bin/kuard /kuard:
------
Dockerfile:31
--------------------
  29 |
  30 |     USER nobody:nobody
  31 | >>> COPY --from=build /go/bin/kuard /kuard
  32 |
  33 |     CMD [ "/kuard" ]
--------------------
error: failed to solve: failed to compute cache key: "/go/bin/kuard": not found
Full logs ``` ➜ kuard git:(master) docker buildx build --platform linux/amd64,linux/arm64 . WARN[0000] No output specified for docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load [+] Building 52.9s (28/29) => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 808B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 64B 0.0s => [linux/arm64 internal] load metadata for docker.io/library/golang:1.12-alpine 1.3s => [linux/arm64 internal] load metadata for docker.io/library/alpine:latest 1.3s => [linux/amd64 internal] load metadata for docker.io/library/alpine:latest 1.4s => [linux/amd64 internal] load metadata for docker.io/library/golang:1.12-alpine 1.3s => [auth] library/golang:pull token for registry-1.docker.io 0.0s => [auth] library/alpine:pull token for registry-1.docker.io 0.0s => [auth] library/golang:pull token for registry-1.docker.io 0.0s => [auth] library/alpine:pull token for registry-1.docker.io 0.0s => [linux/amd64 build 1/7] FROM docker.io/library/golang:1.12-alpine@sha256:3f8e3ad3e7c128d29ac3004ac8314967c5ddbfa5bfa7caa59b0de493fc01686a 0.0s => => resolve docker.io/library/golang:1.12-alpine@sha256:3f8e3ad3e7c128d29ac3004ac8314967c5ddbfa5bfa7caa59b0de493fc01686a 0.0s => CACHED [linux/amd64 stage-1 1/2] FROM docker.io/library/alpine@sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300 0.0s => => resolve docker.io/library/alpine@sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300 0.0s => CACHED [linux/arm64 stage-1 1/2] FROM docker.io/library/alpine@sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300 0.0s => => resolve docker.io/library/alpine@sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300 0.0s => [linux/arm64 build 1/7] FROM docker.io/library/golang:1.12-alpine@sha256:3f8e3ad3e7c128d29ac3004ac8314967c5ddbfa5bfa7caa59b0de493fc01686a 0.0s => => resolve docker.io/library/golang:1.12-alpine@sha256:3f8e3ad3e7c128d29ac3004ac8314967c5ddbfa5bfa7caa59b0de493fc01686a 0.0s => [internal] load build context 0.1s => => transferring context: 311.84kB 0.1s => CACHED [linux/arm64 build 2/7] RUN apk update && apk upgrade && apk add --no-cache git nodejs bash npm 0.0s => CACHED [linux/arm64 build 3/7] RUN go get -u github.com/jteeuwen/go-bindata/... 0.0s => CACHED [linux/arm64 build 4/7] WORKDIR /go/src/github.com/kubernetes-up-and-running/kuard 0.0s => CACHED [linux/amd64 build 2/7] RUN apk update && apk upgrade && apk add --no-cache git nodejs bash npm 0.0s => CACHED [linux/amd64 build 3/7] RUN go get -u github.com/jteeuwen/go-bindata/... 0.0s => CACHED [linux/amd64 build 4/7] WORKDIR /go/src/github.com/kubernetes-up-and-running/kuard 0.0s => [linux/amd64 build 5/7] COPY . . 0.2s => [linux/arm64 build 5/7] COPY . . 0.2s => [linux/amd64 build 6/7] RUN dos2unix build/build.sh 0.2s => [linux/arm64 build 6/7] RUN dos2unix build/build.sh 0.2s => [linux/arm64 build 7/7] RUN build/build.sh 50.7s => CANCELED [linux/amd64 build 7/7] RUN build/build.sh 50.9s => ERROR [linux/arm64 stage-1 2/2] COPY --from=build /go/bin/kuard /kuard 0.0s ------ > [linux/arm64 stage-1 2/2] COPY --from=build /go/bin/kuard /kuard: ------ Dockerfile:31 -------------------- 29 | 30 | USER nobody:nobody 31 | >>> COPY --from=build /go/bin/kuard /kuard 32 | 33 | CMD [ "/kuard" ] -------------------- error: failed to solve: failed to compute cache key: "/go/bin/kuard": not found ```

The code ran fine on my work laptop(Macbook pro without the M1 chip)

Could someone help me with resolving this, I am really looking forward to reading this book but I am not able to run this project 😞

singhprincejeet commented 2 years ago

Figured it out, changed the env to arch to arm 64 in Dockerfile using ENV ARCH=arm64 and it worked.