This is not a duplicate because although the error is same, my use case is different from others.
I am compiling a go application to deploy with docker on:
however,
when i build it on my OSX machine, and send it to linux, I can deploy that executable to docker without any error
Error :
standard_init_linux.go:211: exec user process caused "no such file or directory"
When you compile your go app with cgo
enabled the compiler links dynamically to libstdc
.
However, golang:alpine
image is so small, because it is not using libstdc
but a simplified version of it called musl libc
.
The error message says
standard_init_linux.go:211: exec user process caused "no such file or directory"
If you connect to your image with
$ docker run -it [image] /bin/sh
you can find your executable in let's say /dist/myexec
, but when you try to run that executable, it says err not found
, because of not that it can't find your executable, obviously, but it can't find file libc
.
The solution is to either
disable CGO : use CGO_ENABLED=0
while building
or add
RUN apk add --no-cache libc6-compat
to your Dockerfile
or do not use golang:alpine
To have a all static binary executable, build it with:
$ CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With