Dockerize Go: Scratch Images, Zero Dependencies, Tiny Attack Surface
Go compiles to a single static binary — which means your production container can be literally empty except for your executable. We build Go Dockerfiles that produce scratch or distroless images under 20 MB with zero OS-level CVEs, because there is no OS to scan.
Need this done for your project?
We implement, you ship. Async, documented, done in days.
Why Dockerize Go
Go produces statically linked binaries, which makes it the ideal language for minimal containers. Yet many teams still ship Go apps on golang:latest — a 1.2 GB image packed with compilers and tools you will never use in production.
A properly containerized Go service runs on scratch or gcr.io/distroless/static, weighs 10-20 MB, has no shell to exploit, and starts in milliseconds. The security audit writes itself.
Our Docker Implementation for Go
Two-stage build optimized for static compilation:
- Build stage:
FROM golang:1.22-alpine AS builder— setsCGO_ENABLED=0 GOOS=linux GOARCH=amd64, runsgo mod downloadfirst for layer caching, thengo build -ldflags='-s -w' -o /app ./cmd/server. The-s -wflags strip debug info, shaving 30% off binary size. - Runtime stage:
FROM scratch— copies the binary, a/etc/passwdfile for the non-root user, and CA certificates from the builder (COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/). SetsUSER 65534(nobody).
If the app needs timezone data or DNS resolution, we swap to gcr.io/distroless/static-debian12 instead of scratch. Compose config includes a health check via the app's /healthz endpoint using a sidecar or Docker's built-in HEALTHCHECK with a tiny static binary.
What You Get
- Multi-stage
Dockerfileproducing 10-20 MB images - Scratch or distroless base — zero OS-level CVEs
docker-compose.ymlwith health checks and restart policies- Build caching with
go mod downloadlayer separation - Makefile targets for local build, test, and container build
- CI pipeline with Go module cache and Docker layer cache
Why Anubiz Engineering
Ready to get started?
Skip the research. Tell us what you need, and we'll scope it, implement it, and hand it back — fully documented and production-ready.