0

I have a docker container that runs several services inside it. I want each service to have it's output sent to the console. The is a development container so I want to see all output as I work.

I tried this file:

[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

But it only outputs the supervisord messages and not the messages from the services. I saw another thread where ther sent log messages to /dev/fd/1 so I tried that also and it didn't work.

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

My base image is ubuntu 20.04.

Why cant I get the services log messages into console?

Guerrilla
  • 193
  • 5
  • 18

1 Answers1

2

First, don't use supervisord and docker, pick one or the other, if you are using docker, use docker compose and a split out each service using docker to control the process, but if you're going to do this anyway... I started supervisor with supervisord -n and updated my nginx config to send logs to /dev/stderr and /dev/stdout and everything is working as expected. the startup commands for nginx are sent to /dev/stdout by supervisord and the nginx logs are send to the place configured by nginx, only error_log is configurable for nginx startup parameters, see specific links below.

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 logging

nginx logging

php-fpm logging

memcached logging (verbose)

Jacob Evans
  • 7,636
  • 3
  • 25
  • 55
  • Thanks, I had missed the step of configuring each service to log to stdout. I understand advice to split to separate containers but this is purely for local development and I find it easier to just have it inside a single container. – Guerrilla Feb 24 '21 at 08:37
  • sure, running `docker-compose up` would also give you all the output of each service/container defined as well, and allow you to develop in a real-world setup – Jacob Evans Feb 24 '21 at 08:43