Created
May 27, 2021 22:21
-
-
Save marawannwh/2beed022621b259b8a4983b76bda10e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use the offical golang image to create a binary. | |
# This is based on Debian and sets the GOPATH to /go. | |
# https://hub.docker.com/_/golang | |
FROM golang:1.16-buster as builder | |
# Create and change to the app directory. | |
WORKDIR /app | |
# Retrieve application dependencies. | |
# This allows the container build to reuse cached dependencies. | |
# Expecting to copy go.mod and if present go.sum. | |
COPY go.* ./ | |
# RUN go mod download | |
# Copy local code to the container image. | |
COPY . ./ | |
# Build the binary. | |
RUN go build -v -o server | |
# Use the official Debian slim image for a lean production container. | |
# https://hub.docker.com/_/debian | |
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds | |
FROM debian:buster-slim | |
RUN set -x && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ | |
ca-certificates && \ | |
rm -rf /var/lib/apt/lists/* | |
# Copy the binary to the production image from the builder stage. | |
COPY --from=builder /app/server /app/server | |
# Run the web service on container startup. | |
CMD ["/app/server"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment