Skip to content

[BUGFIX] Send the remaining logs of the services to the container log - #657

Draft
Kanti wants to merge 4 commits into
masterfrom
bugfix/logs-to-container-log
Draft

Kanti wants to merge 4 commits into
masterfrom
bugfix/logs-to-container-log

Conversation

@Kanti

@Kanti Kanti commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Why

#656 sent the logs of PHP-FPM to /docker.stdout and /docker.stderr. An audit of all the other logs of the images, below, found logs that did not reach the container log (docker logs), or not the files of LOG_STDOUT and LOG_STDERR where those are set:

  • sshd logs to syslog with the facility auth, which syslog-ng drops (not facility(auth, authpriv)). A failed login showed up nowhere in the -dev images.
  • What the services print themselves went to the container log also with LOG_STDOUT and LOG_STDERR, because supervisord wrote it to /dev/stdout and /dev/stderr: the output of cron jobs in Alpine, the messages of the Blackfire agent, the output of the start scripts and their hooks, warnings of syslog-ng, start messages of Postfix in Alpine and of PHP-FPM before it opens its log.
  • The main error log of Nginx in Alpine (messages that belong to no server, such as worker process 89 exited on signal 9) went to /docker.stdout, so to the stdout of the container or the file of LOG_STDOUT: the image's own nginx.conf for Alpine has error_log /docker.stdout.

No upstream issue asks for this directly.

The audit also found that cron in Debian and Ubuntu mails or discards the output of its jobs. Fixing that changes how cron behaves (no mail any more), so it is a pull request of its own: #667. This pull request leaves cron as it is.

Audit

Running containers of the published images with the change of #656 on top (its 20-setup-php-fpm-pool.sh run in the image): php, php-dev, php-nginx, php-nginx-dev, php-apache, php-apache-dev, each 8.5 and 8.5-alpine, and base and base-app ubuntu-22.04 with cron, syslog, postfix, ssh and dnsmasq enabled (php-dev with dnsmasq too). In each container: a request straight to PHP-FPM and over http and https through the web server, each calling error_log(), also with XDEBUG_TRIGGER=1; a 404; a request slower than fpm.pool.request_slowlog_timeout=1s; error_log() and a warning in the PHP CLI; a mail with sendmail; a failed ssh login; logger with the facilities user and auth; a cron job of application that writes to stdout and stderr and runs PHP with a warning. Then find / -xdev -newer <marker> -type f after a cron run, and docker logs with stdout and stderr apart. The -dev images ran a second time with LOG_STDOUT and LOG_STDERR, php-dev a third time with PHP_DEBUGGER=blackfire (with the start script of the agent from master).

"Container log" means docker logs, or the files of LOG_STDOUT and LOG_STDERR where they are set.

Log Where it goes now Reaches the container log Change
supervisord's own messages (spawned: 'nginxd', exited: …) stdout of PID 1 (nodaemon, --logfile /dev/null), also with LOG_STDOUT yes (with LOG_STDOUT: stays in docker logs) none: the log of the process manager stays where docker logs shows it; the docs of TZ and of the healthcheck rely on it. Documented.
What the services print themselves: start scripts and hooks (-> Executing …, Setting php-fpm user to application), warnings of syslog-ng, PHP-FPM's Failed implicitly binding to ::, postfix/postlog: starting the Postfix mail system (Alpine), the Blackfire agent, the output of cron jobs on Alpine supervisord: stdout_logfile=/dev/stdout, stderr_logfile=/dev/stderr yes without LOG_*; no with them: in docker logs, not in the files supervisor.d/*.conf of all services: /docker.stdout and /docker.stderr, so they follow LOG_STDOUT and LOG_STDERR
syslog-ng messages from /dev/log and its own (internal()) to pipe("/docker.stdout") (file() with LOG_STDOUT), with [SYSLOG] yes, except: the facilities auth and authpriv are dropped (filter f_filter); what a service sends before syslog-ng listens (about the first second) is lost none to syslog-ng; sshd no longer depends on it (below). The race is left: it only costs start messages (see cron, dnsmasq), and a fix would make each service wait for syslog-ng. Documented.
cron (Debian, Ubuntu): its own messages (CMD, END, (CRON) INFO) syslog yes where syslog-ng runs (the PHP images; base, base-app only if syslog is enabled too); (CRON) INFO (pidfile fd = 3) and (Running @reboot jobs) missing in some runs (race); the PAM session lines are authpriv and dropped none (Debian cron has no other log target); docs: enable syslog with cron in base and base-app
cron (Alpine, BusyBox crond): its own messages syslog yes none
Output of cron jobs, Debian and Ubuntu (stdout, stderr, PHP errors of CLI scripts in jobs) cron mails it with /usr/sbin/sendmail: in php, php-nginx, php-apache (no MTA) discarded, (CRON) info (No MTA installed, discarding output); in the -dev images and in base/base-app with Postfix delivered locally to /var/mail/application or /var/mail/root, which grow no #667, not here
Output of cron jobs, Alpine BusyBox crond passes on its stdout and stderr to the job, i.e. supervisord's pipes yes without LOG_*; no with them (in docker logs) the supervisor.d change above
PHP errors of the CLI (docker exec, docker compose run) stderr of the command (log_errors=1, no error_log) no, by design: the caller sees them; php.error_log gives them a file none (documented since #656)
Postfix syslog (mail); Debian: warnings of newaliases/postsuper, Alpine: postfix/postlog start lines on stderr yes where syslog-ng runs; in base/base-app without syslog: lost none; docs: enable syslog with postfix in base and base-app. Bounces of undeliverable mail go to /var/mail/root: mail, not a log, left.
sshd syslog, facility auth no: syslog-ng drops auth sshd -D -e: sshd logs to its stderr, so to the container stderr or LOG_STDERR, also without syslog-ng
dnsmasq syslog (daemon) yes where syslog-ng runs; its start messages missing in some runs (race), all lost without syslog in base none: --log-facility=- would make dnsmasq exit when SERVICE_DNSMASQ_OPTS sets --log-facility too (illegal repeated flag); docs: enable syslog with dnsmasq in base and base-app
Nginx access log (port 80 and 443) /docker.stdout (vhost.common.d/10-log.conf, access_log of nginx.conf) yes none
Nginx error log of the server (port 80 and 443) /docker.stderr (warn, -dev: info) yes none
Nginx main error log (messages of no server, e.g. worker process … exited on signal 9) Debian: /docker.stderr (notice); Alpine: error_log /docker.stdout in the image's own nginx.conf yes, but on Alpine on stdout and in the file of LOG_STDOUT Alpine nginx.conf: /docker.stderr
Nginx's compiled-in /var/log/nginx links to /var/lib/nginx/logs; nothing written there in the runs n/a none
Apache access log (port 80 and 443) /docker.stdout: CustomLog of conf.d/10-log.conf and the distribution's (other_vhosts_access.log on Debian, access.log in httpd.conf on Alpine), which the build points to /docker.stdout too yes, each request twice in two formats none: which of the two to drop changes a format that users may parse; out of scope
Apache error log (port 80 and 443) /docker.stderr (warn, -dev: info); vhost.ssl.conf sets no log of its own yes none
PHP-FPM master and pool, access log /docker.stderr, /docker.stdout (#656) yes none
PHP errors of PHP-FPM /docker.stderr, through the master (#656) yes none
PHP-FPM slow log slowlog = /docker.stderr, off by default the warning yes; the backtrace only with SYS_PTRACE, otherwise ERROR: failed to ptrace(ATTACH) child …: Operation not permitted none (a Docker default); known issue with cap_add: SYS_PTRACE
Xdebug no xdebug.log; its messages (Could not connect to debugging client) go to PHP's error log yes for PHP-FPM; CLI: stderr of the command none
Blackfire agent --log-file default stderr yes without LOG_*; with them in docker logs the supervisor.d change above
Blackfire probe PHP's error log / stderr ([Error] APM: … Cannot connect to the agent) yes none
docker-healthcheck /proc/1/fd/2 yes (with LOG_STDERR: stays in docker logs) none: documented as container log
Files that grow no file under /var/log changed in any run (Alpine has empty auth.log, error.log, kern.log, mail.log from the build; apk.log/dpkg logs only change with packages); /var/mail/<user> (cron output with Postfix) and /var/mail/root (bounces); state and pid files of Postfix and syslog-ng — /var/mail/<user>: #667; the rest left
/opt/docker/etc/logrotate.d/syslog-ng rotates /var/log/syslog and others; logrotate is not installed and nothing writes these files — none, left
Noise go-replace … Error: no files specified from postfix.d/10-init.sh at every start of Postfix; syslog-ng warnings on stats_freq/use-dns — none, separate fix

What

  • supervisor.d/*.conf of all services (cron, dnsmasq, postfix, ssh, syslog, nginx, apache, php-fpm, blackfire-agent): stdout_logfile=/docker.stdout and stderr_logfile=/docker.stderr instead of /dev/stdout and /dev/stderr. Without LOG_STDOUT and LOG_STDERR, /docker.stdout and /docker.stderr are the stdout and stderr of the container, the same as before; with them, the output goes to the two files. The messages of supervisord itself stay in the container log.
  • provisioning/base/general/bin/service.d/ssh.sh: sshd -D -e, so sshd logs to its stderr, which supervisord passes on, also where no syslog-ng runs.
  • provisioning/nginx/alpine/etc/nginx/nginx.conf: error_log /docker.stderr, as in Debian.
  • Image tests: see below. The hook of syslog-ng writes a line to stdout and one to stderr.
  • Docs:
    • docs/customization.md: a new section "Logs" with where each service logs, what supervisord passes on, that syslog-ng drops auth/authpriv and loses what a service sends before it listens, and that base and base-app need syslog for cron, postfix and dnsmasq. "Cron jobs": docker-service enable syslog cron for base. "supervisord" says to use /docker.stdout and /docker.stderr for a program of your own.
    • docs/environment-variables.md: LOG_STDOUT and LOG_STDERR name what goes there now, and that the messages of supervisord stay in the container log; SERVICE_SSH_OPTS is for sshd -D -e.
    • docs/known-issues.md: a new entry for what stays: the slow log of PHP-FPM, which needs SYS_PTRACE for its backtrace (cap_add).
    • docs/README.md, AGENTS.md: one line each.
  • make generate.

Changes in behaviour for existing users

  • With LOG_STDOUT or LOG_STDERR, what the services print themselves goes to these files and no longer to docker logs: the output of the start scripts and hooks of the services, the output of cron jobs in Alpine, the messages of sshd and the Blackfire agent, start errors of Nginx, Apache and PHP-FPM before they open their logs. docker logs keeps the output of the entrypoint, the messages of supervisord itself and of docker-healthcheck.
    • This widens what LOG_STDOUT and LOG_STDERR mean, on purpose: they stand for the container log as a whole, not for the access and error log of the web server. The messages of syslog-ng, for example of cron and Postfix, already went there before. If LOG_STDOUT points at a file that a tool reads as a pure access log, for example /var/log/apache2/access.log, these lines now land there too. The docs of the two variables and the section "Logs" say so.
    • Without LOG_STDOUT and LOG_STDERR, nothing changes: /docker.stdout and /docker.stderr are the stdout and stderr of the container, and the output stays in docker logs, stdout and stderr apart (new test below).
  • sshd logs to the stderr of the container, without [SYSLOG] in front, also its start message Server listening on 0.0.0.0 port 22. Before, syslog-ng dropped them.
  • Nginx in Alpine writes its main error log to the stderr of the container or the file of LOG_STDERR, not to stdout.

Tests

New image tests, in the environment container, which has LOG_STDOUT and LOG_STDERR:

  • ContainerEnvironmentChecks::testServiceOutputReachesTheFilesFromTheEnvironment (all images; base and base-app start syslog-ng for it): the hook of syslog-ng from Hooks/ writes a line to stdout and one to stderr; they are in the files of LOG_STDOUT and LOG_STDERR.
  • SshChecks::testSshLogsToTheFileFromTheEnvironment (development images): a login of an unknown user over port 2222 fails, and Invalid user image-test-nobody from 127.0.0.1 is in the file of LOG_STDERR.
  • NginxEnvironmentChecks::testNginxMainErrorLogToTheFileFromTheEnvironment (php-nginx, php-nginx-dev): after kill -9 of a worker, [alert] … worker process … exited on signal 9 is in the file of LOG_STDERR, not in that of LOG_STDOUT.

And one without LOG_STDOUT and LOG_STDERR:

  • ContainerEnvironmentChecks::testServiceOutputReachesTheContainerLogWithoutTheEnvironment (all images; a container of its own without LOG_*, which starts syslog-ng where the image does not): the two lines of the hook of syslog-ng are in docker logs, the first on its stdout, the second on its stderr. It passes before and after: it guards the behaviour without LOG_*.

These tests do not check that a line is missing from docker logs: at SERVICE_SUPERVISOR_OPTS=--loglevel=trace of the environment container, supervisord repeats the output of the services in its own messages.

All image tests of each image, before (the published image with the files of master on top, including #656) and after (the same with this change). These runs were made before the output of cron jobs moved to #667; testCronJobOutputReachesTheFilesFromTheEnvironment went with it.

Image Before After
php:8.5, php:8.5-alpine, php-apache:8.5, php-apache:8.5-alpine, php-nginx:8.5 testServiceOutputReachesTheFilesFromTheEnvironment fails pass
php-nginx:8.5-alpine it, and testNginxMainErrorLogToTheFileFromTheEnvironment fail pass
php-dev:8.5, php-dev:8.5-alpine, php-nginx-dev:8.5, php-apache-dev:8.5, php-apache-dev:8.5-alpine it, and testSshLogsToTheFileFromTheEnvironment fail pass
php-nginx-dev:8.5-alpine all three fail pass
base:ubuntu-22.04, base-app:ubuntu-22.04 testServiceOutputReachesTheFilesFromTheEnvironment fails pass

Before, the two lines of the hook were in docker logs, not in the files; for sshd, its file had no line of sshd at all.

No other test changes its result. The other failures in these local runs are the same before and after and come from the older local images: testPhpVersion (PHP 8.5.12), testImagickReportsItsVersion (php:8.5), testDockerImageCleanup and testZicIsInstalled (Alpine), and in the -dev images whose published image is older than #635 and #651 (supervisor.d with startsecs = 0, which the local images keep), testPostfixOptionsFromTheEnvironment and, in some runs either way, testBlackfireAgentRunsWithTheServerCredentials.

The new tests fail on the published images as well (only them run): php-nginx:8.5 and php-apache:8.5-alpine the one of the services, php-dev:8.5 also the one of sshd, php-nginx-dev:8.5-alpine all three, base the one of the services.

How it was verified

In the images with the change on top (amd64): the published image with the files of this branch copied over, its supervisor.d files changed the same way and the 20-setup-php-fpm-pool.sh of #656 run. Where a statement depends on Debian or Alpine, both were checked.

Documented statement Check Result
Alpine: the output of a job goes to the stdout and stderr of the container, or the two files php:8.5-alpine with and without LOG_STDOUT/LOG_STDERR VERIFY-JOB-OUT on stdout or in the file of LOG_STDOUT, VERIFY-JOB-ERR and the PHP warning on stderr or in the file of LOG_STDERR; @reboot jobs too
LOG_STDOUT/LOG_STDERR: supervisord writes there what the services print; its own messages stay in the container log php-nginx:8.5-alpine with both variables and SERVICE_NGINX_OPTS=-Z nginx: invalid option: "Z" in the file of LOG_STDERR, the output of the start scripts and hooks of the services in the file of LOG_STDOUT; docker logs has the output of the entrypoint and the messages of supervisord only
LOG_STDERR: the messages of sshd and the Blackfire agent php-dev:8.5, php-dev:8.5-alpine with PHP_DEBUGGER=blackfire and dummy credentials; base with ssh enabled the errors of the agent (Error sending request to Blackfire API …) in the file, none in docker logs; Server listening on 0.0.0.0 port 22. in the file (base)
SERVICE_SSH_OPTS: sshd -D -e, sshd logs to its stderr php-apache-dev:8.5, php-nginx-dev:8.5-alpine, base: a login of an unknown user; cmdline of sshd Invalid user verify-nobody from 127.0.0.1 port … and Server listening on 0.0.0.0 port 22. on the stderr of the container; /usr/sbin/sshd -D -e
Logs: Nginx and Apache, also for port 443 php-nginx:8.5, php-nginx-dev:8.5-alpine, php-apache-dev:8.5, php-apache:8.5-alpine: https requests for / (403) and a missing page access lines with :443 on stdout, directory index … forbidden / AH01276 on stderr
Logs: the main error log of Nginx goes to /docker.stderr php-nginx-dev:8.5-alpine, php-nginx:8.5: kill -9 of a worker [alert] … worker process … exited on signal 9 on stderr
Logs: syslog-ng drops auth and authpriv, e.g. su su -s /bin/sh application -c true, logger -p auth.info neither in the container log
Logs: what a service sends before syslog-ng listens is lost the start messages of cron and dnsmasq over several starts (audit) (CRON) INFO (pidfile fd = 3) and dnsmasq[…]: started, version … in some starts, missing in others
Logs: at the log level debug, supervisord repeats what the services print php-nginx:8.5 with SERVICE_SUPERVISOR_OPTS=--loglevel=debug DEBG 'syslogd' stdout output: and the line
Known issue: the slow log needs SYS_PTRACE php:8.5, php:8.5-alpine with fpm.pool.request_slowlog_timeout=1s, a request of 3 s, with and without --cap-add SYS_PTRACE without: executing too slow and ERROR: failed to ptrace(ATTACH) child …: Operation not permitted (1); with: the backtrace (sleep() /app/php-test.php:58) in the file of LOG_STDERR
  • After the split: with only the stdout_logfile/stderr_logfile lines of supervisor.d changed in php-nginx:8.5 and the hook of syslog-ng copied in, the two hook lines are on the stdout and stderr of docker logs without LOG_*, and only in the two files with LOG_STDOUT=/tmp/out.log LOG_STDERR=/tmp/err.log.
  • Checks of ci/: the PHPUnit tests of ci/ (341) pass, and PHPStan (level 8) finds nothing.
  • Not verified: arm64, the other PHP versions (8.2 to 8.4, 8.6). This pull request's CI runs the new tests on all images on amd64 and arm64.

Some logs of the services did not reach the container log, or not the
files of LOG_STDOUT and LOG_STDERR:

- Cron in Debian and Ubuntu mails the output of a job. Without a mail
  server it discarded it ("No MTA installed, discarding output"); in the
  development images Postfix delivered it to /var/mail/<user>.
  docker-cronjob now begins /etc/cron.d/webdevops-docker with
  SHELL=/usr/local/bin/docker-cronjob-shell. The new script runs the job
  with /bin/sh and sends its stdout and stderr, line by line, to syslog,
  from where syslog-ng writes them to the container log. It keeps the exit
  code of the job and waits up to 10 seconds for syslog-ng, for @reboot
  jobs, which cron runs as soon as it starts.
- sshd logs to syslog with the facility auth, which syslog-ng drops. It
  now runs with -e and logs to its stderr.
- What the services print to their stdout and stderr, for example the
  output of cron jobs in Alpine, the Blackfire agent and sshd, went to the
  container log also with LOG_STDOUT and LOG_STDERR. supervisord now
  writes it to /docker.stdout and /docker.stderr, which are the stdout and
  stderr of the container without the two variables.
- Nginx in Alpine wrote its main error log, e.g. a worker process that
  ended on a signal, to /docker.stdout; now to /docker.stderr.

The image tests check each case in the environment container. The docs
describe where each service logs, the output of cron jobs, and as known
issues the crontab files of your own in Debian and Ubuntu and the slow log
of PHP-FPM without SYS_PTRACE.
The output of the cron jobs of docker-cronjob changes how cron behaves in
Debian and Ubuntu (no mail), so it moves to #667. A new image test checks that
without LOG_STDOUT and LOG_STDERR the output of the services stays in the
container log.
@Kanti
Kanti removed this pull request from stack #659 November 23, 2026 08:17
…ainer-log

# Conflicts:
#	docker/base/ubuntu-22.04/conf/bin/service.d/ssh.sh
#	docker/base/ubuntu-22.04/conf/etc/supervisor.d/cron.conf
#	docker/base/ubuntu-22.04/conf/etc/supervisor.d/dnsmasq.conf
#	docker/base/ubuntu-22.04/conf/etc/supervisor.d/postfix.conf
#	docker/base/ubuntu-22.04/conf/etc/supervisor.d/ssh.conf
#	docker/base/ubuntu-22.04/conf/etc/supervisor.d/syslog.conf
#	docs/customization.md
#	docs/environment-variables.md
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant