Docker Templates
Go Production Docker Template: Distroless or Scratch, Non-Root, Multi-Arch
Multi-stage Dockerfile and Compose for Go services: static binary, distroless or scratch runtime, non-root, multi-arch builds, self-probing healthcheck.
What you get: 1 file · 11.19 KB · ZIP
See purchase optionsProduct description
A production Docker setup for Go HTTP services. The build stage cross-compiles a static, stripped binary for the target platform (amd64 and arm64 with buildx), stamps the version through ldflags, and the runtime is either distroless static (default) or FROM scratch. Both run as uid 65532 with no shell, so the included service has a -healthcheck mode that probes itself.
What is inside
- Dockerfile with 4 stages: build (CGO off, -trimpath, cache mounts), test (go vet and go test), runtime-scratch (CA bundle, tzdata, passwd entry), runtime (gcr.io/distroless/static-debian12:nonroot).
- compose.yaml: read-only root filesystem, all capabilities dropped, no-new-privileges, 0.5 CPU and 128 MB limits, 25 second stop grace period, log rotation, healthcheck, switch to scratch with one variable, optional Postgres 17 profile.
- Example service using only the standard library: HTTP server timeouts, JSON logs with log/slog, graceful shutdown on SIGTERM, Go 1.22+ method routing for /healthz, /readyz, /version and /api/hello.
- Table-driven tests covering 200, 400, 404 and 405 responses.
- Makefile (build, build-scratch, test, run, multiarch, scan), env.example, README with private modules via BuildKit secrets, cgo notes and a distroless vs scratch comparison.
How it was checked
gofmt, go vet and go test pass on Go 1.25.3. The binary was cross-compiled with the exact command from the Dockerfile and is a statically linked, stripped linux/amd64 ELF of about 6 MB. A native build answered /healthz, /version (with the stamped version) and /api/hello, the -healthcheck mode exited 0 against the server and 1 against a closed port, and SIGTERM produced a clean shutdown. docker compose config validates the Compose file for both runtime targets. The image itself was not built in our environment.
Requirements
Docker Engine 24+ with BuildKit and buildx, Docker Compose v2.24+. Go 1.23+ only to run outside Docker.
Licence
Use in unlimited own and client projects. You may not resell or redistribute the template itself.
What you get
1 file · 11.19 KB
- Go-Production-Docker-Template.zipZIP · 11.19 KB
Docker Templates
Go Production Docker Template: Distroless or Scratch, Non-Root, Multi-Arch
Multi-stage Dockerfile and Compose for Go services: static binary, distroless or scratch runtime, non-root, multi-arch builds, self-probing healthcheck.
Getly opened the uploaded files and found nothing that would stop them opening. It is not a virus scan or a quality rating.
Tags
Frequently asked questions
Do I get access instantly?
Yes. This is a digital product - you can download it right after checkout, straight from your library.
Can I use it for commercial projects?
Yes. Commercial use is allowed: use it in your own business and in things you sell. You may not resell or redistribute the file itself.
What's your refund policy?
You can request a refund within 30 days. If something isn't right, request it from your order and the Getly team reviews it.
What file formats and sizes will I get?
You'll download 1 file - ZIP - 11.19 KB in total.
Do I get free updates?
Yes - when the seller ships a new version, you can re-download the latest files from your library at no extra cost. Check the changelog for recent updates.
Price
$10.00


