From 113213fdd7bfaa3834ff9ad9922290e0dbfd075b Mon Sep 17 00:00:00 2001 From: Martin Koehler Date: Sat, 7 Nov 2020 12:13:58 +0100 Subject: [PATCH 1/2] Allow MailHog to use privileged ports locally MailHog allows to configure the port where it listens e.g. via the environment variable MH_SMTP_BIND_ADDR. However privileged ports are not allowed, since MailHog runs as normal user. Using setcap the MailHog binary is allowed to bind on privileged ports --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8bd1a157..f9041ff3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,13 +6,14 @@ FROM golang:alpine # Install MailHog: RUN apk --no-cache add --virtual build-dependencies \ - git \ + git libcap \ && 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 + && setcap CAP_NET_BIND_SERVICE=+eip /usr/local/bin/MailHog \ + && apk del --purge build-dependencies libcap # Add mailhog user/group with uid/gid 1000. # This is a workaround for boot2docker issue #581, see From 459497d1ea45cbcc1469359b43c3f3062c959d98 Mon Sep 17 00:00:00 2001 From: Martin Koehler Date: Tue, 30 Mar 2021 19:52:41 +0200 Subject: [PATCH 2/2] Dockerfile extract the setcap portion as an additional stage in the Dockerfile build --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index f9041ff3..32148376 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,12 +6,14 @@ FROM golang:alpine # Install MailHog: RUN apk --no-cache add --virtual build-dependencies \ - git libcap \ + 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 \ + && rm -rf /root/gocode +RUN apk --no-cache add --virtual build-dependencies \ + libcap \ && setcap CAP_NET_BIND_SERVICE=+eip /usr/local/bin/MailHog \ && apk del --purge build-dependencies libcap