- Stage 1 ( “builder” ) : Uses a Go env to compile your app into multi linux binaries ( server + workers )
- Stage 2 (”runtime”) : Ships only those binaries into a tiny, secure runtime image.
- Default command runs the API server, but for each worker we override the command in Compose/Kubernetes
Line-by-line explanation
Dockerfile syntax
# syntax=docker/dockerfile:1
Enables modern Dockerfile features & better caching behaviour. Safe default.
Stage 1: Build stage
Base image for compilation
FROM golang:1.22-alpine AS builder
- Uses Go 1.22 on Alpine Linux.
- Names this stage
builder so we can copy artifacts from it later.
Working directory
WORKDIR /src
All subsequent commands run inside /src.
Install build-time packages
RUN apk add --no-cache ca-certificates git
git is needed because some Go modules are fetched via git.
ca-certificates helps with TLS while downloading modules.