9

How to redirect logs of non pid 1 process to dockerlogs with ultimate goal of redirecting them to gelf?

There are 2 processes inside the docker container:

1) pid 1 process

2) non pid 1 process which writes to log file at path

Following docker docs And specifically

The official nginx image creates a symbolic link from /dev/stdout to /var/log/nginx/access.log, and creates another symbolic link from /dev/stderr to /var/log/nginx/error.log, overwriting the log files and causing logs to be sent to the relevant special device instead.

didn't help. Only pid 1 process logs are redirected to dockerlogs

Performed steps:

1ln -sf /dev/stdout _path_ in Dockerfile

2 Running the updated image as container.

3 docker logs -f _containerid_ shows only logs of pid 1 process

There's another official docker source

Which states

Docker supports different logging drivers used to store and/or stream container stdout and stderr logs of the main container process (pid 1)

So it maybe the reason for not seeing the logs of non pid 1 process.

Though, still don't understand why the created symbolic link by ln -sf /dev/stdout /var/log/mysql/error.log hasn't worked.

rok
  • 9,403
  • 17
  • 70
  • 126

1 Answers1

9

I have same issue on the topic. The way I resolve it, you need to start the "ln -s" when docker is running NOT during Docker build (Dockerfile).

Here is my shell bash script

tail -n 0 -q -F /path/folder/*.log >> /proc/1/fd/1 &

Hope helps

kororo
  • 1,972
  • 15
  • 26