-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use official golang as base container #191
Conversation
Thanks! I think there's additional improvements that can be made to the Dockerfile
With the above changes, the Dockerfile would look something like; #
# MailHog Dockerfile
#
FROM golang:1.9-alpine3.7 AS build
WORKDIR /go/src/github.com/mailhog/MailHog
COPY . .
RUN go install
FROM alpine:3.7
# Install ca-certificates, required for the "release message" feature:
RUN apk --no-cache add ca-certificates
# Add mailhog user/group with uid/gid 1000.
# This is a workaround for boot2docker issue #581, see
# https://github.com/boot2docker/boot2docker/issues/581
RUN adduser -D -u 1000 mailhog
USER mailhog
WORKDIR /home/mailhog
ENTRYPOINT ["MailHog"]
# Expose the SMTP and HTTP ports:
EXPOSE 1025 8025
COPY --from=build /go/src/github.com/mailhog/MailHog/LICENSE.md /
COPY --from=build /go/bin/MailHog /usr/local/bin/ Diff/patch for the above (including changes to the diff --git a/.dockerignore b/.dockerignore
index 72e8ffc..f5b25d0 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1 +1,6 @@
-*
+.git
+.dockerignore
+.travis.yml
+docs
+Dockerfile
+Makefile
diff --git a/Dockerfile b/Dockerfile
index 8bd1a15..6af92eb 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,18 +1,16 @@
#
# MailHog Dockerfile
#
+FROM golang:1.9-alpine3.7 AS build
-FROM golang:alpine
+WORKDIR /go/src/github.com/mailhog/MailHog
+COPY . .
+RUN go install
-# Install MailHog:
-RUN apk --no-cache add --virtual build-dependencies \
- git \
- && mkdir -p /root/gocode \
- && export GOPATH=/root/gocode \
- && go get github.com/mailhog/MailHog \
- && mv /root/gocode/bin/MailHog /usr/local/bin \
- && rm -rf /root/gocode \
- && apk del --purge build-dependencies
+FROM alpine:3.7
+
+# Install ca-certificates, required for the "release message" feature:
+RUN apk --no-cache add ca-certificates
# Add mailhog user/group with uid/gid 1000.
# This is a workaround for boot2docker issue #581, see
@@ -27,3 +25,6 @@ ENTRYPOINT ["MailHog"]
# Expose the SMTP and HTTP ports:
EXPOSE 1025 8025
+
+COPY --from=build /go/src/github.com/mailhog/MailHog/LICENSE.md /
+COPY --from=build /go/bin/MailHog /usr/local/bin/ |
To be deterministic we could use precompiled releases (or sources), which would also give us the ability to use version tags. |
By copying it directly from the Git source, the build is tied with the commit you’re building from, and doesn’t require binaries to be built separately. Not sure the project is not maintained, but (as many open source projects) is worked on in spare time of the author/maintainer; I guess @ian-kent is busy, so patience, and give it some time |
Marking as needs verification. While I'm expecting any issues I just want to be 100% this isn't going to break anything |
@tyndyll I'm sure it shouldn't be merged, but instead approach from @thaJeztah #191 (comment) comment should be considered :) |
Note: multi-stage builds may not work for official images: docker-library/official-images#3383 |
The issue with official images is only for the official images itself, and due to the tooling used by the people building the official images (they use a fairly complicated build system, with a dependency graph between all the images, needed to make sure that re-builds are triggered in the right order when updating those images) |
- Use the official golang:alpine image for the build. (see also mailhog#191). - Build and install MailHog from the current repository instead of retrieving it from GitHub. - Statically compile MailHog, so it can be installed without any dependencies. - Disable symbol table and DWARF generation for a smaller binary size. - Build the final Docker image from scratch, adding only the MailHog binary and ca-certificates.
- Use the official golang:alpine image for the build. (see also mailhog#191). - Build and install MailHog from the current repository instead of retrieving it from GitHub. - Statically compile MailHog, so it can be installed without any dependencies. - Disable symbol table and DWARF generation for a smaller binary size. - Build the final Docker image from scratch, adding only the MailHog binary and ca-certificates.
I've tested it and it works properly! |
Merging the official Golang build for now. Will create a new issue to address the points made by @thaJeztah |
This needs to be built and pushed to Docker Hub. |
Yes. Working on getting credentials |
Use official golang as base container
Docker is already providing a well supported base image for Go apps. Those official images are also continuously maintained and scanned for security issues.
Please note that this will also bump the version of Go to 1.9.3 and Alpine 3.6 (by the time of writing).
btw: would be great if you could fullfil the steps to become an "official" image yourself. :)
See also: https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/