Skip to content
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

Docker optimizations #245

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Fale
Copy link

@Fale Fale commented May 27, 2019

Now that #191 got merged, #205 does not apply anymore. This is a rebase of that commit so that it applies cleanly.

I think this is important so that we can slim the delivered image!

blueimp and others added 2 commits May 16, 2019 09:39
- 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.
@Fale
Copy link
Author

Fale commented May 27, 2019

This merge request includes and superseeds #205, while #191 was an alternate route to #219, so both those should be closed imho

@fubarhouse
Copy link

Can you please get this one through?!

@tuanpt-0634
Copy link

tuanpt-0634 commented Aug 12, 2020

This is build result on my computer

mailhog-pull_245                          latest               35f3c13401bb        About an hour ago   9.03MB
mailhog/mailhog                           latest               669347153085        3 years ago         19.1MB

COPY --from=build /go/bin/MailHog /bin/
# Avoid permission issues with host mounts by assigning a user/group with
# uid/gid 1000 (usually the ID of the first user account on GNU/Linux):
USER 1000:1000
ENTRYPOINT ["MailHog"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double checking; should this be either /bin/Mailhog, or should the COPY put the binary at the root (/)?

(didn't test it, perhaps the default PATH takes care of that)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I just ran some test with this branch. Works both with and without the absolute path.

FROM scratch
# ca-certificates are required for the "release message" feature:
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=build /go/bin/MailHog /bin/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LICENSE.md should probably also be copied in the final image (as this is distributing the software, which (I think) requires the license to be included)

*
.git
docs
*.md

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would prevent the license to be copied to the image; perhaps a good idea to rename LICENSE.md to just LICENSE

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or !LICENSE.md

@mblaschke
Copy link

mblaschke commented Sep 30, 2020

Instead of using scratch you might use google's distroless image gcr.io/distroless/static (also provides certs, nsswitch and other stuff for eg. Kuberentes), example:
https://github.com/webdevops/pagerduty-exporter/blob/main/Dockerfile

more information about the distroless images is available on https://github.com/GoogleContainerTools/distroless

@kohenkatz
Copy link

kohenkatz commented Dec 21, 2020

I was able to build this for ARM64 too using these commands (assumes docker buildx environment is already set up):

git fetch origin pull/245/head:pull-245
docker buildx build --platform linux/amd64,linux/arm64 -t registry.example.com/mailhog/mailhog:pull-245 --push .

Can we please get this merged and official builds (including ARM64) released?

@back-2-95
Copy link

Inspired by this PR, we have made this (which we use in daily basis).
https://hub.docker.com/repository/docker/druidfi/mailhog

Here is the Dockerfile: https://github.com/druidfi/docker-images/blob/main/misc/mailhog/Dockerfile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.