-
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
optimize docker image size #76
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# build image | ||
FROM golang:latest | ||
RUN go get -v github.com/mailhog/MailHog && \ | ||
cd /go/src && \ | ||
CGO_ENABLED=0 go build -a -installsuffix cgo -v -o /go/bin/MailHog.o github.com/mailhog/MailHog/main.go | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use Since alpine linux and therefor gliderlabs/alpine docker containers use musl instead of gnu libc your golang binaries will not work inside alpine. so we need build with static linking enabled. |
||
EXPORT /go/bin/ /target | ||
|
||
# run image | ||
FROM alpine:latest | ||
IMPORT /target/ /tmp | ||
RUN cp /tmp/MailHog.o /MailHog | ||
EXPOSE 1025 8025 | ||
CMD ["/MailHog"] | ||
TAG mailhog/mailhog:{{ or .VERSION "latest" }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we want to tag the build with version: rocker build -var VERSION=x.y.z the result will be a tagged image if you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the magic of Rocker is we can separate the build and runtime image.
the build image container all resource or dependencies required at build time.
once the build success, copy it to the runtime image which based on alpine.
so the final image is alpine + MailHog executable binary.