Menu

1 / 4

Cross-Compiling Go for Alpine vs Distroless: The CGO_ENABLED Decision Tree

DEV Community·Gabriel Anhaia·6 months ago
#RI0qJuA4
#question#cgorequired#go#binary#build
Reading 0:00
15s threshold

Book: Hexagonal Architecture in Go

Also by me: Thinking in Go (2-book series) — Complete Guide to Go Programming + Hexagonal Architecture in Go

My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools

Me: xgabriel.com | GitHub

You've seen this one. The CI green-lights the build. The

image pushes. The pod boots. And then the first request to

an external service hangs for thirty seconds and times out

with a DNS error that contradicts what nslookup inside the

container just told you.

The pod is on Alpine. The binary was built with CGO_ENABLED=1

on Debian. The C runtime that compiled it was glibc. The C

runtime trying to run it is musl. They are not the same

runtime, and Go's net package quietly notices.

The decision tree behind that one line in your Dockerfile,

CGO_ENABLED=0 or CGO_ENABLED=1 , decides whether you can

ship to Alpine, to distroless, or to scratch.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.