Skip to content

Instantly share code, notes, and snippets.

@cnp96
Created December 14, 2021 00:02
Show Gist options
  • Save cnp96/73f95a34698c1cb286b6915bd0465f1e to your computer and use it in GitHub Desktop.
Save cnp96/73f95a34698c1cb286b6915bd0465f1e to your computer and use it in GitHub Desktop.
Docker build for Go app
FROM golang:1.16.4-alpine as base
WORKDIR /app/go
COPY . .
RUN go mod download
FROM base as image-dev
RUN go get github.com/cosmtrek/air
EXPOSE 9000
CMD $(go env GOPATH)/bin/air
FROM base as builder
RUN mkdir dist
RUN go build -o dist/web .
FROM alpine:3.15 as image-prod
WORKDIR /app
COPY --from=builder ./app/go/dist/ ./
EXPOSE 9000
CMD ./web
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment