简体   繁体   English

Dockerfile rsyslog

[英]Dockerfile rsyslog

I have implemented a dockerfile to have a postfix that logs using rsyslog, but it raises an error while running.我已经实现了一个 dockerfile 来拥有一个使用 rsyslog 记录日志的后缀,但是它在运行时引发了一个错误。

Output Error:输出错误:

tail: cannot open '/var/log/mail.log' for reading: No such file or directory
tail: no files remaining

Here is my Dockerfile:这是我的 Dockerfile:

FROM ubuntu:16.04

RUN apt-get update && apt-get install -y libsasl2-modules postfix rsyslog && rm -rf /var/lib/apt/lists/*

COPY main.cf /etc/postfix/
COPY ca-certificates.crt /etc/ssl/certs/

EXPOSE 25

CMD service rsyslog start && service postfix start && tail -f /var/log/mail.log

Any help will be greatly appreciated.任何帮助将不胜感激。

Remove these lines:删除这些行:

RUN touch /dev/xconsole && chgrp syslog /dev/xconsole && chmod 664 /dev/xconsole
RUN service rsyslog restart

And update CMD to start rsyslog at first:并首先更新CMD以启动rsyslog

CMD service rsyslog start && service postfix start && tail -f /var/log/mail.log

Because RUN executes command during the image build whereas CMD executes command in the running container and you need to run rsyslogd in a running container.因为RUN在镜像构建期间执行命令,而CMD在正在运行的容器中执行命令,您需要在正在运行的容器中运行 rsyslogd。

Result Dockerfile can look like this:结果Dockerfile可能如下所示:

FROM ubuntu:16.04

RUN apt-get update && apt-get install -y libsasl2-modules postfix rsyslog; \
    rm -rf /var/lib/apt/lists/*
RUN echo "[smtp.gmail.com]:587 email@gmail.com:password" > /etc/postfix/sasl_passwd; \
    postmap /etc/postfix/sasl_passwd; \
    sed -i '/relayhost*/c\relayhost = [smtp.gmail.com]:587' /etc/postfix/main.cf; \
    sed -i '/smtp_sasl_auth_enable*/c\smtp_sasl_auth_enable = yes' /etc/postfix/main.cf; \
    sed -i '/smtp_sasl_security_options*/c\smtp_sasl_security_options = noanonymous' /etc/postfix/main.cf; \
    sed -i '/smtp_sasl_password_maps*/c\smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd' /etc/postfix/main.cf; \
    sed -i '/smtp_tls_security_level*/c\smtp_tls_security_level = encrypt' /etc/postfix/main.cf; \
    sed -i '/smtp_tls_CAfile*/c\smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt' /etc/postfix/main.cf

EXPOSE 587

CMD service rsyslog start && service postfix start && tail -f /var/log/mail.log

Build it: docker build -t postfix -f Dockerfile.postfix .构建它: docker build -t postfix -f Dockerfile.postfix .

And when you run it: docker run -it --rm --name postfix postfix当你运行它时: docker run -it --rm --name postfix postfix

... then you have mail log in console: ...然后您在控制台中有邮件登录:

 * Starting enhanced syslogd rsyslogd                                    [ OK ] 
 * Starting Postfix Mail Transport Agent postfix                                                                                                                                                                   postfix: Postfix is running with backwards-compatible default settings
postfix: See http://www.postfix.org/COMPATIBILITY_README.html for details
postfix: To disable backwards compatibility use "postconf compatibility_level=2" and "postfix reload"
                                                                                                                                                                                                            [ OK ]
Sep 26 20:11:01 6009a2e3d206 postfix[111]: Postfix is running with backwards-compatible default settings
Sep 26 20:11:01 6009a2e3d206 postfix[111]: See http://www.postfix.org/COMPATIBILITY_README.html for details
Sep 26 20:11:01 6009a2e3d206 postfix[111]: To disable backwards compatibility use "postconf compatibility_level=2" and "postfix reload"
Sep 26 20:11:01 6009a2e3d206 postfix/master[156]: daemon started -- version 3.1.0, configuration /etc/postfix
Sep 26 20:11:01 6009a2e3d206 postfix/pickup[159]: error: open file /etc/mailname: No such file or directory
Sep 26 20:11:01 6009a2e3d206 postfix/qmgr[160]: error: open file /etc/mailname: No such file or directory

You can also check the mail log using exec command: docker exec postfix cat /var/log/mail.log .您还可以使用 exec 命令检查邮件日志: docker exec postfix cat /var/log/mail.log This can be helpful when running container as a daemon ( -d flag).这在将容器作为守护进程( -d标志)运行时会很有帮助。


Regarding the rsyslogd-2039: Could not open output pipe error - you can ignore it.关于rsyslogd-2039: Could not open output pipe错误 - 您可以忽略它。

But if you don't want to ignore it you can update your CMD and have it like this:但是如果你不想忽略它,你可以更新你的CMD并让它像这样:

CMD touch /dev/xconsole && chgrp syslog /dev/xconsole && chmod 664 /dev/xconsole && service rsyslog start && service postfix start && tail -f /var/log/mail.log

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM