Supervisord 服务未输出到 docker-compose 控制台

Supervisord 服务未输出到 docker-compose 控制台

我有一个 Docker 容器,里面运行着多个服务。我希望每个服务的输出都发送到控制台。这是一个开发容器,所以我想在工作时看到所有输出。

我试过这个文件:

[supervisord]
nodaemon=true
 
[program:sshd]
command=/usr/sbin/sshd -D
autostart=true
autorestart=true
 
[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"
priority=900
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
username=www-data
autorestart=true
autostart=true

[program:php-fpm]
command=/usr/sbin/php-fpm7.4 -F
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autostart=true
autorestart=true
priority=5


[program:memcached]
command=/usr/bin/memcached -u root
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autostart=true
autorestart=true
priority=200

但它只输出监督消息,而不输出来自服务的消息。我看到另一个线程发送了日志消息,/dev/fd/1所以我也尝试了,但没有成功。

stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true

我的基础图像是 ubuntu 20.04。

为什么我无法将服务日志消息发送到控制台?

答案1

首先,不要使用supervisord和docker,选择其中一个,如果您使用docker,请使用docker compose并使用docker拆分每个服务来控制进程,但如果您无论如何都要这样做...我启动了supervisor并supervisord -n更新了我的nginx配置以将日志发送到/ dev / stderr和/ dev / stdout,一切都按预期工作。 nginx的启动命令由supervisord发送到/ dev / stdout,nginx日志发送到nginx配置的位置,只有error_log可用于配置nginx启动参数,请参阅下面的具体链接。

root@6534bf4b8d3c:/# supervisord -n
/usr/lib/python3/dist-packages/supervisor/options.py:470: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
  self.warnings.warn(
2021-02-23 23:54:30,673 CRIT Supervisor is running as root.  Privileges were not dropped because no user is specified in the config file.  If you intend to run as root, you can set user=root in the config file to avoid this message.
2021-02-23 23:54:30,674 INFO Included extra file "/etc/supervisor/conf.d/guerrilla.conf" during parsing
2021-02-23 23:54:30,676 INFO RPC interface 'supervisor' initialized
2021-02-23 23:54:30,676 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2021-02-23 23:54:30,676 INFO supervisord started with pid 5239
2021-02-23 23:54:31,678 INFO spawned: 'nginx' with pid 5241
2021-02-23 23:54:32,686 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
127.0.0.1 - - [23/Feb/2021:23:54:35 -0500] "GET / HTTP/1.1" 200 612 "-" "curl/7.68.0"

sshd 日志

nginx 日志

php-fpm 日志

memcached 日志记录(详细)

相关内容