I have a Go 1.18 app which runs without issues in my WSL2 Ubuntu, but fails to run in a Docker container with the error message exec /app: no such file or directory
.
My Dockerfile (slightly adapted from another Go 1.12 app that works without issues) is:
FROM golang:1.18-alpine AS build
WORKDIR /app
COPY go.mod ./
COPY go.sum ./
RUN go mod download
COPY source/*.go ./
RUN go build -o /app
FROM gcr.io/distroless/static-debian11
COPY --from=build /app /app
USER nonroot:nonroot
CMD ["/app"]
Building it shows no errors. I tried adding GOOS=linux
and GOARCH=amd64
and building with --platform linux/amd64
but it makes no difference (and should not be necessary I think?). I switched from Distroless to Debian, same issue.
The file /app
exists (11 mb, 755
). file /app
gives this output:
app: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, Go BuildID=UsV_orwX-S3Rwh16P1VH/6u2iHufDhnUYUkHBp0rE/2xn48wuW047ZRbQ7qPIy/ihQgooFxjsMgMzYGE-8h, not stripped
I can't figure out where I'm going wrong. What is the issue here?
CodePudding user response:
Seems to be caused by using go-ping/ping. Switching the build image to golang:1.18
(not Alpine) and the final image to gcr.io/distroless/base-debian11
fixes the issue.