I\'ve got a Go binary I\'m trying to run on the Alpine Docker image.
This works fine for the Docker Go binary.
docker run -it alpine:3.3 sh
apk add -
RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
Since the musl and glibc so are compatible, you can make this symlink and it will fix the missing dependency.
I compiled go binary in alpine with these options
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o [name of binary]
It worked.
When building under Debian 9 (Stretch) / Go 1.10.2 and running under Alpine 3.7.0:
CGO_ENABLED=0 go build
Neither GOOS=linux
nor GOARCH=amd6
was necessary.
Alternatively, you can (meanwhile) use the golang:alpine
image from Docker Hub to compile and run your code.
docker run -v ${YOUR_CODE_PATH}:/go/src/example -it golang:alpine sh
cd src/example
go build .
ldd example
/lib/ld-musl-x86_64.so.1 (0x7f677fcf7000)
libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f677fcf7000)
You can install libc6-compat
RUN apk add --no-cache libc6-compat
Depending on the nature of the program, you might want to compile your go program with static link options, such as the following:
-x -a -tags netgo -installsuffix netgo
Afterwards you do not need to worry about linking the correct libraries.