Collect only from STDERR when using Docker syslog logging driver

1.7k views Asked by At

We are running our Docker containers with the syslog driver as follows:

docker run -d --name <<container_name>> --log-driver syslog <<image_name>>

This makes the Docker daemon to forward messages from both STDOUT and STDERR to syslog. Is there a way for me to pick only STDOUT or only STDERR to be captured? I checked the "-a" flag, but it does not work when used with "-d" - which is essential for us. I checked this issue [https://github.com/docker/docker/issues/7440], but it seems to be about docker logs command which is not applicable in our case (when using syslog driver).

Is there a way to achieve selective forwarding when using the syslog log-driver in a container running in the background?

1

There are 1 answers

4
Nathaniel Waisbrot On BEST ANSWER

Sounds like your best option is to throw away the output that you don't want:

RUN someCode > /dev/null

This will discard all the output to STDOUT (when you use RUN without an array it evaluates your command using the shell) and leaves STDERR alone. Unfortunately, if you were hoping to have STDOUT also available somewhere you are out of luck. (You could direct STDOUT to a file, but then you'd really want to start thinking about log rotation too and that gets to be a lot of work.)