Skip to content

Instantly share code, notes, and snippets.

@antonioalfa22

antonioalfa22/docker

Created Sep 25, 2020
Embed
What would you like to do?
go-rest-template Dockerfile
FROM golang:1.12-alpine
RUN apk add --no-cache git gcc g++
# Set the Current Working Directory inside the container
WORKDIR /app
# We want to populate the module cache based on the go.{mod,sum} files.
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
# Build the Go app
RUN go build -o ./out/app ./cmd/api/main.go
# This container exposes port 8080 to the outside world
EXPOSE 3000
# Run the binary program produced by `go install`
CMD ["./out/app"]
#################################################################
FROM golang:1.12-alpine AS build_base
RUN apk add --no-cache git git gcc g++
# Set the Current Working Directory inside the container
WORKDIR /tmp
# We want to populate the module cache based on the go.{mod,sum} files.
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
# Build the Go app
RUN go build -o ./out/app ./cmd/api/main.go
# Start fresh from a smaller image
FROM alpine:3.9
RUN apk add ca-certificates
COPY --from=build_base /tmp/out/app /app/restapi
# This container exposes port 8080 to the outside world
EXPOSE 3000
# Run the binary program produced by `go install`
CMD ["/app/restapi"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment