Skip to content

Commit 317c44c

Browse files
Fix Docker build: statically link CGO binary for distroless
The CGO-enabled binary was dynamically linked against musl libc from Alpine, but the distroless runtime image uses glibc. This caused 'no such file or directory' at runtime because the dynamic linker couldn't be found. Fix by passing -linkmode external -extldflags '-static' to produce a fully static binary.
1 parent d608c4b commit 317c44c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN --mount=type=cache,target=/var/cache/apk \
1313
RUN --mount=type=cache,target=/go/pkg/mod \
1414
--mount=type=cache,target=/root/.cache/go-build \
1515
--mount=type=bind,target=. \
16-
CGO_ENABLED=1 go build -ldflags="-s -w -X main.version=${VERSION} -X main.commit=$(git rev-parse HEAD) -X main.date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
16+
CGO_ENABLED=1 go build -ldflags="-s -w -linkmode external -extldflags '-static' -X main.version=${VERSION} -X main.commit=$(git rev-parse HEAD) -X main.date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
1717
-o /bin/github-mcp-server ./cmd/github-mcp-server
1818

1919
# Make a stage to run the app

0 commit comments

Comments
 (0)