I was trying to get a minimal example go app running inside a docker container.
But I kept getting exec /app: no such file or directory
when running the container.
I checked and double checked all my paths in the image where I built and copied my application data, even looked inside the container with interactive shell to verify my app
was there but nothing worked.
My Dockerfile:
# syntax=docker/dockerfile:1
# BUILD-STAGE
FROM golang:1.17-alpine as build
WORKDIR /go/app
COPY . .
RUN go mod download
RUN go build -o /go/bin/app
# RUN-STAGE
FROM gcr.io/distroless/static-debian11
COPY --from=build /go/bin/app .
EXPOSE 8080
CMD ["./app"]
After several hours of try and error I finally tried to add CGO_ENABLED=0
to my go build command.... and it worked!
My question is now.... why exactly does this happen? There was no error when I built my image with CGO implicitly enabled and I even verified that the binary was copied into my second stage! Why does the runtime say there is no such file when it was built using CGO, but can find it easily when it was built with CGO disabled?