$ tree
.
├── Dockerfile
├── configs
│ ├── main.cf
│ └── sasl_passwd
├── docker-compose.yml
└── entrypoint.sh
docker-compose.yml
version: '3.8'
services:
docker-ubuntu-postfix-example:
build:
context: ./
dockerfile: dockerfile
image: docker-ubuntu-postfix-example-image: lastes
container_name: docker-ubuntu-postfix-example-container
volumes:
# Postfixの設定をマウント
- type: bind
source: ./configs/main.cf
target: /etc/postfix/main.cf
# SASL認証のパスワードをマウント
- type: bind
source: ./configs/sasl_passwd
target: /etc/postfix/sasl_passwd
Dockerfile
FROM ubuntu:20.04 RUN apt update && apt upgrade -y # postfix install RUN DEBIAN_FRONTEND=noninteractive apt install postfix -y # SMTPにはSMTP AUTHが必要 # SMTP AUTHの為のSASLにはCyrus SaslとCyrus IAMPを使う RUN apt install sasl2-bin -y RUN DEBIAN_FRONTEND=noninteractive apt install cyrus-imapd -y # コンテナ起動のスクリプト COPY ./entrypoint.sh / ENTRYPOINT ["/entrypoint.sh"]
entrypoint.sh
#!/bin/bash # postfix起動 postfix start # Postfixは/var/spool/postfixにchrootするので、 # /etc/resolv.confではなく/var/spool/postfix/etc/resolv.confを見に行く。 cp /etc/resolv.conf /var/spool/postfix/etc/resolv.conf # SASL認証用テーブル作成 chown root:root /tec/postfix/sasl_passwd postmap /etc/postfix/sasl_passwd # postfixの設定を反映させる postfix reload # コンテナの起動を維持 tail -f /dev/null
entrypoint.sh
#!/bin/bash # postfix起動 postfix start # Postfixは/var/spool/postfixにchrootするので、 # /etc/resolv.confではなく/var/spool/postfix/etc/resolv.confを見に行く。 cp /etc/resolv.conf /var/spool/postfix/etc/resolv.conf # SASL認証用テーブル作成 chown root:root /tec/postfix/sasl_passwd postmap /etc/postfix/sasl_passwd # postfixの設定を反映させる postfix reload # コンテナの起動を維持 tail -f /dev/null
main.cf
# ログの出力設定 mainlog_file = /var/log/mail.log # SMTPリレーの設定 relayhost = smtp_sasl_auth_enable = smtp_sasl_mechanism_filter = smtp_sasl_security_options = smtp_sasl_password_maps =
なるほどー、結構考えないといけないな…