← All notes · 2026-07-24 · 3 min read

Reproducible Static Go Builds Without Local Toolchains

Using ephemeral golang:alpine containers with CGO_ENABLED=0 and stripped symbols for tiny server binaries.

dockergoops

Keeping build hosts clean

Installing full language toolchains on small VPS instances clutters disk space and drifts across OS upgrades. Running a one-shot build container mounts only the source tree and leaves a single static ELF binary behind.

Passing -ldflags='-s -w' drops DWARF debug tables and cuts binary size by roughly 30% without affecting stack traces or runtime behaviour.

docker run --rm -v "$PWD:/src" -w /src \
  -e CGO_ENABLED=0 golang:alpine \
  go build -ldflags="-s -w" -o /src/app .