Created
May 30, 2020 21:06
-
-
Save efontan/891d158b45dee8bbf1480ef5ed58485f to your computer and use it in GitHub Desktop.
Golang Dockerfile example
This file contains hidden or 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
# Start from golang base image | |
FROM golang:1.13 as builder | |
# Install git. | |
# Git is required for fetching the dependencies. | |
RUN apk update && apk add --no-cache git | |
# Set the current working directory inside the container | |
WORKDIR /app | |
# Copy files | |
COPY . /app | |
# Build the Go app | |
RUN CGO_ENABLED=0 GOOS=linux GOPROXY=https://proxy.golang.org go build -o app cmd/myapp/main.go | |
# Start a new stage from scratch | |
FROM alpine:latest | |
# mailcap adds mime detection and ca-certificates help with TLS (basic stuff) | |
RUN apk --no-cache add ca-certificates mailcap && addgroup -S app && adduser -S app -G app | |
USER app | |
WORKDIR /app | |
COPY --from=builder /app/app . | |
# Expose port to the outside world | |
EXPOSE 8080 | |
#Command to run the executable | |
ENTRYPOINT ["./app"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment