Docker: Enabling mailing in php:apache (running WordPress)

Starting from

When using the php:apache image from https://hub.docker.com/_/php/ image mail support was not enabled. On my docker host postfix is already enabled and configured to accept and forward mails from my docker containers. So I should be able to send mails. When I decided to install Wordpress by myself, I ended up with this Dockerfile and did config stuff using a volume over /var/www/html:
FROM php:apache

# start here to see which apt and php packages are needed: https://github.com/docker-library/wordpress

RUN apt-get update && apt-get -y install libjpeg-dev libpng-dev \
  && docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
  && docker-php-ext-install gd mysqli opcache \
  && apt-get clean \

# set recommended PHP.ini settings
# see https://secure.php.net/manual/en/opcache.installation.php
RUN { \
                echo 'opcache.memory_consumption=128'; \
                echo 'opcache.interned_strings_buffer=8'; \
                echo 'opcache.max_accelerated_files=4000'; \
                echo 'opcache.revalidate_freq=2'; \
                echo 'opcache.fast_shutdown=1'; \
                echo 'opcache.enable_cli=1'; \
        } > /usr/local/etc/php/conf.d/opcache-recommended.ini

# Apache Module aktivieren
RUN a2enmod rewrite expires

# Install WordPress by yourself
At the end I realized that mails are not working. Php's answer when asking for the sendmail_path is this:
root@9f3b8b59bd67:/var/www/html# php -i | grep sendmail_path
sendmail_path =>  -t -i  =>  -t -i
And Php mail() result is this:
root@9f3b8b59bd67:/var/www/html# php -r "mail('test@some.where', 'Subject', 'Body');"
sh: 1: -t: not found

The manual approach first:

Entering the container:
docker exec -ti <contianer> bash
Then installing sSMTP
apt-get update
apt-get install ssmtp vim
#you need vim for editing the config file
vi /etc/ssmtp/ssmtp.conf
and configuring it. Here is my ssmtp.conf
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=youradmin-email@maildomain.com

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=172.18.0.1:25
# This is the hub in my docker swarm network

# Where will the mail seem to come from?
#rewriteDomain=

# The full hostname
hostname=put.your.fqdn.hostname.here

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generat:wqed From: address
FromLineOverride=YES
Changing the sendmail_path for Php is easy as there is no php.ini by now:
echo "sendmail_path = /usr/sbin/ssmtp -t" >> /usr/local/etc/php/php.ini
After restarting the Apache
service apache2 graceful
Php is responding with a valid sendmail_path
root@9f3b8b59bd67:/var/www/html# php -i | grep sendmail_path
sendmail_path => /usr/sbin/ssmtp -t => /usr/sbin/ssmtp -t
Now Php mail() and also Wordpress mailing is working fine ;-).

The new Dockerfile:

You need to have the above ssmtp.conf file to build the image.
FROM php:apache

# start here to see which apt and php packages are needed: https://github.com/docker-library/wordpress

RUN apt-get update && apt-get -y install ssmtp libjpeg-dev libpng-dev \
  && docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
  && docker-php-ext-install gd mysqli opcache \
  && apt-get clean \

# set recommended PHP.ini settings
# see https://secure.php.net/manual/en/opcache.installation.php
RUN { \
                echo 'opcache.memory_consumption=128'; \
                echo 'opcache.interned_strings_buffer=8'; \
                echo 'opcache.max_accelerated_files=4000'; \
                echo 'opcache.revalidate_freq=2'; \
                echo 'opcache.fast_shutdown=1'; \
                echo 'opcache.enable_cli=1'; \
        } > /usr/local/etc/php/conf.d/opcache-recommended.ini
# and adding a php.ini with the senmail path to ssmtp
RUN echo 'sendmail_path = /usr/sbin/ssmtp -t' >> /usr/local/etc/php/php.ini
# now copy the local ssmtp.conf file
COPY ssmtp.conf /etc/ssmtp/ssmtp.conf

# Apache Module aktivieren
RUN a2enmod rewrite expires

# Install WordPress by yourself