Back to course

Dockerizing Your Go Microservice

Go (Golang) for Cloud-Native Microservices

Putting it in a Container

Go is famous for producing a single static binary. This makes Docker images extremely small.

The Multi-Stage Dockerfile:

dockerfile

Build stage

FROM golang:1.21-alpine AS builder WORKDIR /app COPY . . RUN go build -o main .

Final stage

FROM alpine:latest COPY --from=builder /app/main . CMD ["./main"]

This results in an image of ~15MB instead of 800MB!