【问题标题】:Seeing logs from PID != 1查看来自 PID != 1 的日志
【发布时间】:2018-04-19 15:41:01
【问题描述】:

我的 docker 容器正在运行一个带有 gunicorn 的 django 应用程序。

root@72981b4f355e:/usr/src/app# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMDq
root         1     0  0 15:32 ?        00:00:00 /usr/local/bin/python /usr/local/bin/gunicorn MyApp.wsgi:application --bind 0.0.0.0:8000 --workers 3
root         9     1  1 15:32 ?        00:00:02 /usr/local/bin/python /usr/local/bin/gunicorn MyApp.wsgi:application --bind 0.0.0.0:8000 --workers 3
root        11     1  1 15:32 ?        00:00:02 /usr/local/bin/python /usr/local/bin/gunicorn MyApp.wsgi:application --bind 0.0.0.0:8000 --workers 3
root        12     1  1 15:32 ?        00:00:02 /usr/local/bin/python /usr/local/bin/gunicorn MyApp.wsgi:application --bind 0.0.0.0:8000 --workers 3
root        21     0  0 15:35 ?        00:00:00 bash
root        28    21  0 15:35 ?        00:00:00 ps -ef

日志什么也不显示,因为工人(产生日志的人)不是 PID1。

如何查看工作人员的日志? Gunicorn 启动如下:

exec gunicorn MyApp.wsgi:application \
    --bind 0.0.0.0:8000 \
    --workers 3

【问题讨论】:

    标签: python docker logging gunicorn


    【解决方案1】:

    对于访问日志,您可以添加--access-logfile ---capture-output,如果您想查看工作人员标准输出。您可能还需要设置 PYTHONUNBUFFERED=1 环境变量。

    来源:http://docs.gunicorn.org/en/stable/settings.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-06
      • 2018-09-22
      • 1970-01-01
      • 2015-06-02
      • 2022-01-06
      • 2021-06-26
      • 2019-09-07
      相关资源
      最近更新 更多