Skip to content

Instantly share code, notes, and snippets.

@wattanakorn495
Last active April 21, 2022 08:06
Show Gist options
  • Save wattanakorn495/85460cc78a63336a001e9c9c6cd5e0db to your computer and use it in GitHub Desktop.
Save wattanakorn495/85460cc78a63336a001e9c9c6cd5e0db to your computer and use it in GitHub Desktop.
multi stage docker example
FROM golang:1.16-alpine as builder
LABEL maintainer="Wattanakorn Intanon <watttanakorn.in@avilon.co.th>"
RUN apk update && apk add gcc git
RUN mkdir /mqtt-aggregator
WORKDIR /mqtt-aggregator
COPY go.mod .
COPY go.sum .
COPY . .
RUN go build ./...
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o mqtt-aggregator
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /app/
COPY --from=builder /mqtt-aggregator/mqtt-aggregator .
ENTRYPOINT ["./mqtt-aggregator"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment