我试图在dockerfile中实现postfix,但是当我试图发送一封邮件(地址解析失败)时,它失败了。我需要重新配置对接网络还是只配置后缀主配置?
发送电子邮件:
sendmail to@email.com
From: from@email.com
Subject: theSubject
This is the message
.输出错误:
postfix/error[573]: 322CC760259: to=, orig_to=, relay=none, delay=15, delays=15/0/0/0.1, dsn=4.3.0, status=deferred (address resolver failure)后缀主配置(main.cf)
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
readme_directory = no
# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
# fresh installs.
compatibility_level = 2
# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = meron
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = $myhostname, meron, localhost.localdomain, , localhost
relayhost = [smtp.gmail.com]:587
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
# Enable SASL authentication
smtp_sasl_auth_enable = yes
# Disallow methods that allow anonymous authentication
smtp_sasl_security_options = noanonymous
# Location of sasl_passwd
smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passd
# Enable STARTTLS encryption
smtp_tls_security_level = encrypt
# Location of CA certificates
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crtDockerfile:
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y libsasl2-modules postfix && apt-get -y install rsyslog; \
rm -rf /var/lib/apt/lists/*;
CMD touch /dev/xconsole && chgrp syslog /dev/xconsole && chmod 664 /dev/xconsole
# RUN service rsyslog restart
RUN echo "[smtp.gmail.com]:587 email@gmail.com:password" > /etc/postfix/sasl_passwd
RUN postmap /etc/postfix/sasl_passwd
RUN sed -i '/relayhost*/c\relayhost = [smtp.gmail.com]:587' /etc/postfix/main.cf
RUN sed -i '/smtp_sasl_auth_enable*/c\smtp_sasl_auth_enable = yes' /etc/postfix/main.cf
RUN sed -i '/smtp_sasl_security_options*/c\smtp_sasl_security_options = noanonymous' /etc/postfix/main.cf
RUN sed -i '/smtp_sasl_password_maps*/c\smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd' /etc/postfix/main.cf
RUN sed -i '/smtp_tls_security_level*/c\smtp_tls_security_level = encrypt' /etc/postfix/main.cf
RUN sed -i '/smtp_tls_CAfile*/c\smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt' /etc/postfix/main.cf
# CMD /etc/init.d/postfix restart && tail -f /var/log/syslog
EXPOSE 25
# CMD service rsyslog start && service postfix start && tail -f /var/log/mail.log
CMD touch /dev/xconsole && chgrp syslog /dev/xconsole && chmod 664 /dev/xconsole && service rsyslog start && service postfix start && tail -f /var/log/mail.log任何帮助都将不胜感激。
发布于 2018-10-03 15:06:07
您可以通过向--network="host"添加D0作为选项,而不是用-p参数映射端口,从而将对接桥网络的容器带来,从而使用主机的网络。
对于坞-组合,您可以为特定的服务添加network_mode: "host"而不是ports: & networks:。
例如,当我在本地/dev环境上运行PHP容器时。
Docker CLI
docker run --rm --network="host" -v $(pwd):/app MyVendor/phpfpm71 my_command
Docker撰写:
phpfpm71:
image: MyVendor/phpfpm71
volumes:
- ./app:/app
network_mode: "host"发布于 2018-10-03 13:29:09
我在main.cf中将网关Ip地址添加到mydestination配置中。
工作得很好。;)
https://serverfault.com/questions/933459
复制相似问题