【问题标题】:Dockerfile rsyslogDockerfile rsyslog
【发布时间】:2018-10-05 22:52:06
【问题描述】:

我已经实现了一个 dockerfile 来拥有一个使用 rsyslog 记录日志的后缀,但它在运行时会引发错误。

输出错误:

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

这是我的 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

任何帮助将不胜感激。

【问题讨论】:

    标签: docker dockerfile rsyslog


    【解决方案1】:

    删除这些行:

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

    并首先更新CMD 以启动rsyslog

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

    因为RUN 在镜像构建期间执行命令,而CMD 在运行容器中执行命令,您需要在运行容器中运行 rsyslogd。

    结果 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
    

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

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

    ...然后你有邮件登录控制台:

     * 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
    

    您还可以使用 exec 命令检查邮件日志:docker exec postfix cat /var/log/mail.log。这在将容器作为守护进程运行时会很有帮助(-d 标志)。


    关于rsyslogd-2039: Could not open output pipe 错误 - 您可以忽略它。

    但如果你不想忽略它,你可以更新你的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
    

    【讨论】:

    • 一切正常,除非我在这样的 EXPOSE 命令之前添加 COPY / ADD(COPY main.cf /etc/postfix/),结果为tail: cannot open '/var/log/mail.log' for reading: No such file or directory
    • 我试过了,它有效。它也适用于不正确的 main.cf 文件并显示 * Starting enhanced syslogd rsyslogd [ OK ] * Starting Postfix Mail Transport Agent postfix postmulti: fatal: /etc/postfix/main.cf, line 1: missing '=' after attribute name: "test" Postfix 由于不正确的配置文件而显示错误但是 rsyslog 正在运行并且 /var/log/mail.log文件已创建并且容器在没有退出的情况下运行。从我的角度来看,您在其他地方有问题。您是否使用与答案中完全相同的 Dockerfile 进行尝试?
    • 我不知道这个 rsyslog 有什么问题,必须有一个解决方案,因为它只是随机运行良好,有时它没有,我真的不知道为什么。但这是我的最终和简单的 Dockerfile,但问题仍然存在。此外,每当我尝试更新它时,它只会引发错误。
    猜你喜欢
    • 2016-08-10
    • 2011-12-02
    • 1970-01-01
    • 2013-12-30
    • 1970-01-01
    • 1970-01-01
    • 2013-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多