Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

https://hub.docker.com/r/tecnativa/postfix-relay/

apt purge postfix mailutils
apt autoremove
rm /etc/postfix/ -R
apt install mailutils

Docker-Run:

docker container run -d \
    --name "postfix" \
    -v /opt/postfix/data:/var/spool/postfix \
    -v /opt/postfix/logs:/var/log/ \
    -p 25:25 \
    -e MAIL_RELAY_HOST='smtp.gmail.com' \
    -e MAIL_RELAY_PORT='587' \
    -e MAIL_RELAY_USER='user@gmail.com' \
    -e MAIL_RELAY_PASS='pwd' \
    tecnativa/postfix-relay

Docker-Compose:

WD=/opt/postfix
mkdir -p $WD/{mnt,setup}
cd $WD/setup
cat << 'EOF' >docker-compose.yaml
version: '3.7'

services:
 postfix:
    container_name: postfix
    hostname: postfix
    image: tecnativa/postfix-relay
    ports:
      - '25:25'
    volumes:
      - type: bind
        source: /opt/postfix/data/
        target: /var/spool/postfix
      - type: bind
        source: /opt/postfix/logs/
        target: /var/log/
      - type: bind
        source: /opt/postfix/mnt/
        target: /mnt

    environment:
      - 'TZ=America/Whitehorse'
      - 'MAIL_RELAY_HOST=smtp.gmail.com'
      - 'MAIL_RELAY_PORT=587'
      - 'MAIL_RELAY_USER=uname@gmail.com'
      - 'MAIL_RELAY_PASS=pwd'
      - 'MAIL_CANONICAL_DOMAINS=gmail.com'
      - 'MAIL_NON_CANONICAL_DEFAULT=gmail.com'
EOF
chmod +x docker-compose.yaml

SystemD:

Docker-Run:

cat << 'EOL' >/lib/systemd/system/postfix.service
[Unit]
Description=PostFix_Docker
Requires=docker.service network-online.target

[Service]
Restart=on-abnormal
ExecStart=/usr/bin/docker start -a postfix
ExecStop=/usr/bin/docker stop -t 2 postfix

[Install]
WantedBy=multi-user.target
EOL
systemctl enable postfix
systemctl start postfix
systemctl status postfix

Docker-Compose:

WD=/opt/postfix/setup
cat << EOF >$WD/postfix.service.setup.sh
cat << EOL >/lib/systemd/system/postfix.service
[Unit]
Description=postfix_Docker
Requires=docker.service network-online.target

[Service]

Restart=on-abnormal
ExecStart=/usr/bin/docker-compose --project-name postfix --project-directory $WD -f $WD/docker-compose.yaml up
ExecStop=/usr/bin/docker-compose --project-name postfix --project-directory $WD -f $WD/docker-compose.yaml stop

[Install]
WantedBy=multi-user.target
EOL
systemctl enable postfix
systemctl start postfix
EOF
chmod +x $WD/postfix.service.setup.sh
$WD/postfix.service.setup.sh
  • No labels