0

I'm trying to get postfix working in a docker container on a raspberry pi. The following works

ENTRYPOINT service rsyslog restart && service postfix restart && sleep 2s && tail /var/log/syslog -f

But if I instead use the following, which is meant to run postfix in the foreground (according to the documentation, and linked from serverfault)

ENTRYPOINT postfix start-fg

then it starts up, but any attempt to send mail results in fatal: unknown service: smtp/tcp


My master.cf contains

# service type  private unpriv  chroot  wakeup  maxproc command + args
smtp       inet  n       -       y       -       -       smtpd

but having read many other issues around chroot, I tried turning that off, with no success.

I have also checked that smtp exists in both /etc/services and /var/spool/postfix/etc/services and that permissions are open for reading. I make sure of this with

RUN ln -snf /etc/services /var/spool/postfix/etc/services
-rw-r--r-- 1 root root 18774 Feb  3 23:28 /var/spool/postfix/etc/services
-rw-r--r-- 1 root root 18774 Feb 10  2019 /etc/services
#grep smtp /var/spool/postfix/etc/services
smtp        25/tcp      mail
submissions 465/tcp     ssmtp smtps urd # Submission over TLS [RFC8314]
#grep smtp /etc/services
smtp        25/tcp      mail
submissions 465/tcp     ssmtp smtps urd # Submission over TLS [RFC8314]


My full dockerfile

FROM --platform=linux/arm/v7 debian:stable-slim
RUN apt-get update
RUN apt-get install postfix rsyslog -y
COPY etc /etc # I have main.cf, mcaster.cf, virtual, and mailname copying in
# Build the virtual.db database file
RUN postmap /etc/postfix/virtual
# This gets smtp working https://serverfault.com/questions/655116/postfix-fails-to-send-mail-with-fatal-unknown-service-smtp-tcp
RUN ln -snf /etc/services /var/spool/postfix/etc/services
EXPOSE 25
ENTRYPOINT service rsyslog restart && service postfix restart && sleep 2s && tail /var/log/syslog -f
#ENTRYPOINT postfix start-fg

I would really prefer to use start-fg both for best practices in having a single process in the container, and that it will make syslog log management cleaner.


Please comment if I've not included something important or if there are useful logs I can grab. I'm intermediate level on linux, so I'll do my best to get logs and traces but may need some guidance.

1 Answer 1

1

Sorry I'm pretty new to this but i'll give a shot: when you use postfix start-fg that will start the postfix process in chroot environment. Postfix needs access to some files in /etc (like one you mentioned is /etc/services). Based on postfix documentation:

Note that a chrooted daemon resolves all filenames relative to the Postfix queue directory (/var/spool/postfix). For successful use of a chroot jail, most UNIX systems require you to bring in some files or device nodes. The examples/chroot-setup directory in the source code distribution has a collection of scripts that help you set up Postfix chroot environments on different operating systems.

So it is the responsiblity of the user to make sure to populate the chroot jail (getting all the files and libraries) necessary for postfix to work as expected. Here is the script provided by postfix to setup the chroot environment. You can see it copies files from /etc as well as some libraries.

#! /bin/sh

# LINUX2 - shell script to set up a Postfix chroot jail for Linux
# Tested on SuSE Linux 5.3 (libc5) and 7.0 (glibc2.1)

# Other testers reported as working:
#
# 2001-01-15 Debian sid (unstable)
#            Christian Kurz <[email protected]>

# Copyright (c) 2000 - 2001 by Matthias Andree
# Redistributable unter the MIT-style license that follows:
# Abstract: "do whatever you want except hold somebody liable or change
# the copyright information".

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

# 2000-09-29
# v0.1: initial release

# 2000-12-05
# v0.2: copy libdb.* for libnss_db.so
#       remove /etc/localtime in case it's a broken symlink
#       restrict find to maxdepth 1 (faster)

# Revision 1.4  2001/01/15 09:36:35  emma
# add note it was successfully tested on Debian sid
#
# 20060101 /lib64 support by Keith Owens.
#

CP="cp -p"

cond_copy() {
  # find files as per pattern in $1
  # if any, copy to directory $2
  dir=`dirname "$1"`
  pat=`basename "$1"`
  lr=`find "$dir" -maxdepth 1 -name "$pat"`
  if test ! -d "$2" ; then exit 1 ; fi
  if test "x$lr" != "x" ; then $CP $1 "$2" ; fi
} 

set -e
umask 022

POSTFIX_DIR=${POSTFIX_DIR-/var/spool/postfix}
cd ${POSTFIX_DIR}

mkdir -p etc lib usr/lib/zoneinfo
test -d /lib64 && mkdir -p lib64

# find localtime (SuSE 5.3 does not have /etc/localtime)
lt=/etc/localtime
if test ! -f $lt ; then lt=/usr/lib/zoneinfo/localtime ; fi
if test ! -f $lt ; then lt=/usr/share/zoneinfo/localtime ; fi
if test ! -f $lt ; then echo "cannot find localtime" ; exit 1 ; fi
rm -f etc/localtime

# copy localtime and some other system files into the chroot's etc
$CP -f $lt /etc/services /etc/resolv.conf /etc/nsswitch.conf etc
$CP -f /etc/host.conf /etc/hosts /etc/passwd etc
ln -s -f /etc/localtime usr/lib/zoneinfo

# copy required libraries into the chroot
cond_copy '/lib/libnss_*.so*' lib
cond_copy '/lib/libresolv.so*' lib
cond_copy '/lib/libdb.so*' lib
if test -d /lib64; then
  cond_copy '/lib64/libnss_*.so*' lib64
  cond_copy '/lib64/libresolv.so*' lib64
  cond_copy '/lib64/libdb.so*' lib64
fi

postfix reload
3
  • Thanks, that sounds plausible. I'll give it a whirl on the weekend and report back. After some more refined searching based on your feedback, I found something that suggests using Alpine sets some of that up for you, where Debian doesn't, so I'll try that too
    – Simon
    Feb 26, 2021 at 17:45
  • You're definitely on the right track. I managed to get to the point where it would start, but then couldn't get reverse DNS lookups working inside the chrooted smtp (this is a raspberry pi, maybe some scripts weren't handling multiple architectures properly). I also realized there were 2 smtp entries in master.cf. Turning off chroot for both of them solved my problem (it's in docker, do I really need chroot?). Marking as Answer as it definitely identified the problem correctly
    – Simon
    Feb 28, 2021 at 12:15
  • Glad you got it working! I agree: inside a docker container chroot is redundant.
    – bmccormick
    Mar 1, 2021 at 15:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .