-
Notifications
You must be signed in to change notification settings - Fork 513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Static linking with Alpine image vs. dynamic linking with Debian bullseye image #453
Comments
If you run |
My hunch is that in Alpine, it's default to disabling CGO due to having no C compiler, so it generates a more portable executable than it does in Debian where it can default to cgo. The next test would be to add |
Also, in the future, these sorts of questions/requests would be more appropriately posted to a dedicated support forum, such as the Docker Community Slack, Server Fault, Unix & Linux, or Stack Overflow. |
For ldd debug-go-distroless
linux-vdso.so.1 (0x00007ffd4794a000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007ff7d8ab5000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff7d8a93000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff7d88be000)
/lib64/ld-linux-x86-64.so.2 (0x00007ff7d8ad5000) For ldd debug-go-distroless
/lib/ld-musl-x86_64.so.1: debug-go-distroless: Not a valid dynamic program I don't really know about linking, but I assume that the binary was statically linked in the case of alpine. If I use the following Dockerflie: FROM golang:1.20 AS builder
WORKDIR /go/src/app
ENV CGO_ENABLED=0
COPY . .
RUN go build -ldflags="-w -s" It links statically either way. Thanks for the hints! |
I'm sorry if this was the wrong place to ask for help. I generally know if I should file a bug or ask on a support-channel. In this case though, I was sure that this is a bug. It's not intuitive to figure out that |
@tim-hilt Just a note about |
Hi there! I recently came across a strange issue, when trying to build a Go binary with the official
golang:1.20
/golang:1.20.0-bullseye
image. I wanted to run the image withdistroless/static-debian11
, but on execution, I only saw the messagefile not found
.The error can be reproduced with the following Dockerfile (found in this repository: https://github.com/tim-hilt/debug-go-distroless):
full reproduction:
Strangely I could execute the binary if I built the image with
golang:1.20-alpine
, which is counter-intuitive, since the distroless-image as well asgolang:1.20
are based on Debian 11.I opened up an issue on the distroless-repository (GoogleContainerTools/distroless#1227). One maintainer pointed out, that the binary was statically linked on Alpine, but dynamically linked when built on Debian.
How is this possible?
The text was updated successfully, but these errors were encountered: