This project demonstrates different approaches to building minimal Docker images using Go applications. It includes examples of building images with:
scratchbase imagedistrolessbase image
The goal of this project is to showcase how to create minimal, secure, and efficient Docker images for Go applications. Since Go compiles to a single static binary, it's ideal for use with minimal base images like scratch and distroless.
- Smaller size: Faster downloads and less storage.
- Security: Reduced attack surface due to fewer packages and tools.
- Efficiency: Less bloat, better performance.
Uses the scratch base image, which is literally empty. The final image contains only the compiled Go binary.
Uses Google's distroless base image, which includes only the runtime dependencies needed to run the application (e.g., CA certificates), without shell or package managers.
GOOS=linux go build -o main .docker build -f Dockerfile.scratch -t demo-scratch .docker build -f Dockerfile.distroless -t demo-distroless .docker run -p 8080:8080 demo-scratch
docker run -p 8080:8080 demo-distrolessmain.go: Simple HTTP server written in Go.go.mod: Go module definition.Dockerfile.scratch: Dockerfile using scratch base image.Dockerfile.distroless: Dockerfile using distroless base image.README.md: This file.