2

Given is a very simple Dockerfile, build and run on Windows 11. The dockerfile has two stages, first the building stage, and then the actual deployable container.

FROM golang:1.17 AS builder
WORKDIR /app
COPY . .
RUN go build -o myapp .         # build /app/myapp

FROM alpine:3.14
RUN apk add --no-cache ca-certificates
COPY --from=builder /app/myapp /myapp
EXPOSE 8080
ENTRYPOINT ["/myapp"]

Running the container fails with the following error:

/myapp: not found

I inspected the first stage, it generated an executable file called myapp with 5984 bytes. I can run and execute it there.

I also inspected the second stage and I can verify that /myapp exists with 5984 and the correct execution bits. Being in inspection mode via sh I cannot execute /myapp since it gives me the same error. Any idea what might cause this?

Daniel Stephens
  • 2,371
  • 8
  • 34
  • 86
  • 2
    You're building the binary against a Debian-based image, but running against an Alpine image with a different C library stack. [Go-compiled binary won't run in an alpine docker container on Ubuntu host](https://stackoverflow.com/questions/36279253/go-compiled-binary-wont-run-in-an-alpine-docker-container-on-ubuntu-host) discusses a similar case of building a binary on the host, for example. – David Maze Apr 17 '23 at 11:32
  • Thanks, I would accept that as an answer. That worked. – Daniel Stephens Apr 18 '23 at 01:27

1 Answers1

-2

There might be several reasons which are causing the issue, try one of the solution:

  1. Particularly in Windows 11, running the Alpine Linux image (alpine:3.14) might be the issue itself. Try with another image.
  2. Try adding the chmod +x /myapp before the ENTRYPOINT ["/myapp"] it helps you to check whether /myapp is executable inside the container.
  • Thanks for your reply. But there is no issue running alpine with Windows. If so, Docker would be broken. Additionally, a permission issue would result in a different error. – Daniel Stephens Apr 18 '23 at 18:02