Dockerizing Go Apps

Docker makes Go apps portable across environments. A typical Dockerfile for a Go app:

FROM golang:1.20 AS builder
WORKDIR /app
COPY . .
RUN go build -o app

FROM alpine
COPY --from=builder /app/app /app
ENTRYPOINT ["/app"]
  • Build image: docker build -t myapp .
  • Run container: docker run -p 8080:8080 myapp
← PrevNext →