Standard_init_linux.go:195: exec user process caused "no such file or directory"

Using a FROM scratch container I am getting this error:

standard_init_linux.go:195: exec user process caused "no such file or directory"

My dockerfile is simple:

FROM scratch
ADD main /
CMD ["/main"]

main is a go binary. It works just fine with a hello world app, but fails for larger projects.

I built the go binary using these flags:

CGO_ENABLED=0
GOOS=linux

And I’ve also tried adding -ldflags '-w -extldflags "-static"'

The binary is building just fine and works in a regular Linux container.

This error message doesn’t give me much of a clue what might be the error. Any ideas what would be causing a file to not be found in such a simple dockerfile?

1 Like

scratch doesn’t have the go runtime?? maybe

A compiled static binary doesn’t need the go runtime. Also, as I mentioned, a simple app (e.g. hello world) works fine.

i would docker attach to the container and look around to see what the problem might be…

i understand about static libraries, but clearly something is different with this executable.

Thanks for the reply. This is a FROM scratch container so you cannot attach in. Also, there is only 1 file, main which is clearly added in the Dockerfile.

I’m confused why this would be an issue with the executable, the error I am getting is with Docker not being able to find a file. This seems like a Docker bug. Is there somewhere I should report it?

Try building your go binary with GOARCH=386 in addition to GOOS=linux.

I had exactly the same problem. I ended up with configuring my repo (because I’m using both Windows and Linux for work)

git config --global core.eol lf
git config --global core.autocrlf input

cloning it again (not sure this step is needed) and building go executable with env vars

$ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build

I used before. Now

FROM scratch

COPY go-app /

EXPOSE 8080

CMD ["/go-app"]

works. Check this github issue too

2 Likes

this help me with CGO_ENABLED=0

1 Like

Same as @javahuang - once I did this it worked:

export CGO_ENABLED=0

(I was building golang executable on Ubuntu and trying to run inside Alpine-based container)

1 Like

Thanks @vladkras this works for me.

1 Like