Commit 5cb8a2e1 by Alin Voinea

Merge pull request #1 from DanielM-gh/master

refs #31595: add Chaperone, use Centos 7, remove example folder
parents 4ac9ede1 383ed618
FROM centos:6
FROM centos:7
RUN yum -y install postfix mailx cyrus-sasl cyrus-sasl-plain python-setuptools python-pip rsyslog
RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 && \
yum updateinfo -y && \
yum install -y epel-release && \
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 && \
yum install -y python34-devel postfix cyrus-sasl cyrus-sasl-plain mailx && \
yum clean all
VOLUME ["/var/log"]
RUN curl https://bootstrap.pypa.io/get-pip.py | python3.4 && \
pip3 install chaperone
ADD postfix.sh /postfix.sh
RUN mkdir -p /etc/chaperone.d
COPY chaperone.conf /etc/chaperone.d/chaperone.conf
CMD ["sh", "-c", "/postfix.sh"]
COPY docker-setup.sh /docker-setup.sh
RUN chmod +x /docker-setup.sh
ENTRYPOINT ["/usr/bin/chaperone"]
......@@ -2,7 +2,7 @@
Available tags: [latest](https://github.com/eea/eea.docker.postfix/blob/master/Dockerfile), [eionet](https://github.com/eea/eea.docker.postfix/blob/master/eionet/Dockerfile).
This image is a CentOS 6 container running postfix preconfigured for SMTP relay authentication. It runs as an open relay mail server inside the Docker Containers internal network, so it can be used by any container to send emails through the remote relay.
This image is a CentOS 7 container running postfix preconfigured for SMTP relay authentication. It runs as an open relay mail server inside the Docker Containers internal network, so it can be used by any container to send emails through the remote relay.
The hostname of the postfix server is set in the environment variable `MTP_HOST` and is mandatory. Postfix will run as an open relay server only if the variables below are also set.
......@@ -23,37 +23,20 @@ Using the mount directive ```-v /etc/localtime:/etc/localtime:ro``` will make su
## Example usage
In the `example` folder, there is an example centos container than can be used to test connectivity.
cd example
docker build -t example .
docker run --rm -it -v /etc/localtime:/etc/localtime:ro --link=postfix:postfixcontainer example
# from commandline:
$ mail test@example.com
From the postfix container ("postfix"):
# from an application, python:
$ python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import smtplib
>>> s = smtplib.SMTP('postfixcontainer')
>>> import smtplib, os
>>> s = smtplib.SMTP(os.getenv('HOSTNAME'))
>>> s.sendmail('test@mydomain.com', ['user@example.com'], 'test')
{}
## Existing container configuration
If you have an existing container that makes use of `/usr/bin/sendmail` to send emails, and you want to use this postfix image instead, you must modify your `Dockerfile` to :
Install mailx/ssmtp:
From another application container ("app"):
# RUN apt-get install -y mailx ssmtp
or
# RUN yum install -y mailx ssmtp
Modify and copy / mount the `/etc/ssmtp.conf` file (see: https://github.com/eea/eea.docker.postfix/blob/master/example/ssmtp.conf). Change `mailhub` directive to the name of the postfixcontainer.
docker run --rm -it -v /etc/localtime:/etc/localtime:ro --name=app --link=postfix:postfixcontainer app_image
# ADD ssmtp.conf /etc/ssmtp.conf
You can check the example image for more details.
# from an application, python:
$ python
>>> import smtplib
>>> s = smtplib.SMTP('postfixcontainer')
>>> s.sendmail('test@mydomain.com', ['user@example.com'], 'test')
setup.service: {
service_groups: INIT,
command: "/docker-setup.sh"
}
postfix.service: {
service_groups: IDLE,
command: "postfix start"
}
console.logging: {
selector: "*.warn",
stdout: true
}
#!/bin/bash
# Set up user
# configure postfix
function setup_conf_and_secret {
postconf -e 'smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.trust.crt'
postconf -e "relayhost = [$MTP_RELAY]:$MTP_PORT"
......@@ -23,8 +24,4 @@ else
postconf -e 'mynetworks = 127.0.0.1/32 192.168.0.0/16 172.16.0.0/12 10.0.0.0/8'
fi
service rsyslog start
service postfix start
touch /var/log/maillog
tail -f /var/log/maillog
newaliases
FROM centos:6
RUN yum install -y mailx ssmtp
ADD ssmtp.conf /etc/ssmtp/ssmtp.conf
CMD ["bash"]
#
# /etc/ssmtp.conf -- a config file for sSMTP sendmail.
#
# See the ssmtp.conf(5) man page for a more verbose explanation of the
# available options.
#
# The person who gets all mail for userids < 500
# Make this empty to disable rewriting.
root=postmaster
# The place where the mail goes. The actual machine name is required
# no MX records are consulted. Commonly mailhosts are named mail.domain.com
# The example will fit if you are in domain.com and your mailhub is so named.
mailhub=postfixcontainer
# Where will the mail seem to come from?
#RewriteDomain=
# The full hostname
#Hostname=
# Set this to never rewrite the "From:" line (unless not given) and to
# use that address in the "from line" of the envelope.
FromLineOverride=YES
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment