Last active
November 23, 2019 17:38
-
-
Save mwmahlberg/6af4cb8edc56a517b599a59a6b1b767e 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
FROM golang:1.12.0 | |
ENV SRC_DIR=/go/src/vk_acceptor/ | |
ADD . $SRC_DIR | |
# 1. Use workdir instead of `cd`, as cd is only valid for the current `RUN`. | |
WORKDIR $SRC_DIR | |
# 2. Use /usr/local/bin (or sbin) as per FHS. Adhere to the principle of least suprise - this is what you expect, too, or don't you? | |
# 3. Use `&&` instead of `;` to connect commands to ensure that the following command is only exeecuted | |
# if the preceding command was successfull. If not, the whole command will return a non-zero exit code. | |
RUN export GO111MODULE=on && env && go env && go get -u && go build -o application && cp application /usr/local/bin/ && chmod +x /usr/local/bin/application | |
# Use something according to FHS instead! Most likely, somthing under /var | |
WORKDIR /app | |
ENTRYPOINT ["/usr/local/bin/application"] |
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
FROM golang:1.12-alpine as build | |
ENV SRC_DIR=/go/src/vk_acceptor/ | |
ADD . $SRC_DIR | |
WORKDIR $SRC_DIR | |
RUN export GO111MODULE=on && go get -u && go build -o application | |
FROM alpine:3.10 | |
ENV SRC_DIR=/go/src/vk_acceptor/ | |
COPY --from=build $SRC_DIR/application /usr/local/bin/application | |
# With workdir, you can denote where application will be relative | |
# in the filesystem. Say you start in tmp, and create a file "foo", | |
# it will be created in "/tmp/foo". | |
WORKDIR /tmp | |
ENTRYPOINT ["/usr/local/bin/application"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
Dockerfile.twostage
is a simple example of creating a slimmer docker image, getting rid of all the build time dependencies. Furthermore, I used an alpine base image here, as this produces smaller images, too.