From 5a1fd390f13d32d07aaf11382e8534105ae6fbf2 Mon Sep 17 00:00:00 2001 From: Erik Huelsmann Date: Fri, 22 Dec 2023 13:03:09 +0100 Subject: [PATCH] Use the container gateway address as the SMTP host The value 172.17.0.1 is the default gateway on the default Docker network. However, when using this image with 'docker-compose', a new network is created, which means that the IP address of the gateway is different by definition. Because the network is created at the same time as the containers, the IP address isn't available when the YAML definition is created. This approach replaces the static approach with a dynamic approach executed at first container startup. --- Dockerfile | 6 ++++-- start.sh | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index c4c9111..7af5cc7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -78,7 +78,7 @@ RUN set -x ; \ DEBIAN_FRONTEND="noninteractive" apt-get -y update && \ DEBIAN_FRONTEND="noninteractive" apt-get -y upgrade && \ DEBIAN_FRONTEND="noninteractive" apt-get -y install \ - wget ca-certificates gnupg \ + wget ca-certificates gnupg iproute2 \ $( cat /tmp/derived-deps ) \ libclass-c3-xs-perl \ texlive-plain-generic texlive-latex-recommended texlive-fonts-recommended \ @@ -110,7 +110,9 @@ WORKDIR /srv/ledgersmb # Configure outgoing mail to use host, other run time variable defaults ## MAIL -ENV LSMB_MAIL_SMTPHOST 172.17.0.1 +# '__CONTAINER_GATEWAY__' is a magic value which will be substituted +# with the actual gateway IP address +ENV LSMB_MAIL_SMTPHOST __CONTAINER_GATEWAY__ #ENV LSMB_MAIL_SMTPPORT 25 #ENV LSMB_MAIL_SMTPSENDER_HOSTNAME (container hostname) #ENV LSMB_MAIL_SMTPTLS diff --git a/start.sh b/start.sh index 2f193c1..d1fecdc 100755 --- a/start.sh +++ b/start.sh @@ -67,7 +67,6 @@ if [[ -n "$LSMB_HAVE_DEPRECATED" ]]; then echo "!!! DEPRECATED \$SSMTP_* PARAMETERS WILL BE REMOVED in the 1.9 image!!!" fi - if [[ ! -f ./local/conf/ledgersmb.yaml ]]; then cat <./local/conf/ledgersmb.yaml paths: @@ -105,6 +104,12 @@ EOF if [[ -n "$LSMB_MAIL_SMTPHOST" ]] then + if [[ "$LSMB_MAIL_SMTPHOST" == "__CONTAINER_GATEWAY__" ]] + then + LSMB_MAIL_SMTPHOST="$(ip route | awk '/default/ { print $3 }')" + export LSMB_MAIL_SMTPHOST + fi + cat <./local/conf/ledgersmb.000.yaml mail: transport: