Last active
September 18, 2021 06:03
-
-
Save percybolmer/cee5694d51b83eb096c59b667b6d48da to your computer and use it in GitHub Desktop.
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
# We add as builder to name our build stage. This is needed so that our second build can refer to it | |
FROM golang:1.15 as builder | |
LABEL maintainer="PercyBolmer@medium" | |
#ARG is used during the Image build | |
ARG port=8080 | |
# Assign Environment variabel PORT the value of port. The user running the container can then override this with the -e flag | |
ENV PORT=${port} | |
RUN mkdir /app | |
COPY main.go /app | |
WORKDIR /app | |
RUN go build -o helloer . | |
EXPOSE ${PORT} | |
# Build a second Image based on our first Image, but only copy our needed files | |
# Removing all necessary files, commands etc is not only saving memory, but | |
# also good for security reasons. | |
FROM scratch | |
# copy the compiled binary named helloer | |
COPY --from=builder /app/helloer . | |
# arguments that can be overridden | |
CMD [ "./helloer"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment