Docker

Supervisord 服務未輸出到 docker-compose 控制台

  • February 24, 2021

我有一個 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

但它只輸出supervisord消息,而不是來自服務的消息。我看到另一個執行緒向其中發送日誌消息,/dev/fd/1所以我也嘗試了,但沒有成功。

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

我的基礎鏡像是 ubuntu 20.04。

為什麼我不能將服務日誌消息輸入控制台?

首先,不要使用 supervisord 和 docker,選擇一個或另一個,如果您使用的是 docker,請使用 docker compose 並使用 docker 拆分每個服務來控製過程,但如果您無論如何都要這樣做.. . 我啟動了主管supervisord -n並更新了我的 nginx 配置以將日誌發送到 /dev/stderr 和 /dev/stdout 並且一切都按預期工作。nginx的啟動命令由supervisord發送到/dev/stdout,nginx日誌發送到nginx配置的地方,nginx啟動參數只能配置error_log,具體連結見下文。

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 日誌記錄(詳細)

引用自:https://serverfault.com/questions/1054459