Deploying Go Applications: The Smallest Docker Images You’ll Ever Ship
Go compiles to a single static binary, perfect for containers. Build 10 MB images and deploy them to your VPS with zero-downtime rollouts. Go was made for this Go compiles to a single statically linked binary with no runtime, no interpreter and no system dependencies. That makes it the best-case scenario for containerization: the final image is your binary plus a few kilobytes of metadata, it…
Go compiles to a single static binary, making it ideal for container deployment. The resulting image is small—under 15 MB—thanks to the -ldflags= -s -w flag, which strips debug symbols and reduces the binary size. Build processes are efficient, with dependency downloads cached across code changes. Dockerfiles can be optimized to use golang:1.24-alpine AS build, copying go.mod/go.sum before source files, and then building the binary with CGO_ENABLED=0.
Distroless images provide additional benefits, including CA certificates, tzdata, and a nonroot user, all within a 2 MB footprint. This eliminates common "works locally, fails in prod" issues. Graceful shutdown and health checks are easily implemented in the binary itself using Go.
Zero-downtime deployments become straightforward, requiring only a /healthz handler and container health check. The binary cooperates by listening on port 8080 and gracefully shutting down when a SIGTERM or interrupt signal is received. This approach allows deployments to overlap old and new containers, ensuring no dropped requests.
Scaling is simple, as a 10 MB image can be hosted on a 2 GB VPS, hosting a small fleet of Go services each idling at 10 to 30 MB of RSS. Cross-compilation to ARM servers is also straightforward, by setting GOARCH=arm64. This results in a consistent Dockerfile across different hardware architectures.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.