Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log to syslog / console in macOS from Docker container?

I set my Docker container set to send logs to the hosts logs on CentOS 7 (with --log-driver syslog). I'd like to replicate this on macOS (Sierra). But it doesn't show up anywhere, seemingly.

$ docker run --log-driver syslog -it busybox sh
/ # logger "Hello world!"
/ # exit

And:

$ sudo cat /var/log/system.log | grep "Hello world"
Password:
$

What configuration is necessary to make it possible for any Docker system logging command for any arbitrary container to appear in a log file on macOS?


I can view these types of default system logging if I do not configure log-driver. But Ruby's syslog implementation must log differently.

$ docker run --log-driver syslog -it centos /bin/bash
# yum install ruby -y
# ruby -e "require 'syslog/logger'; log = Syslog::Logger.new 'my_program'; log.info 'this line will be logged via syslog(3)'"
# exit
$ sudo tail -n 10000 /var/log/system.log | grep "syslog(3)"
$ 
like image 275
Sam Avatar asked Oct 30 '17 14:10

Sam


1 Answers

It depends on how you are logging your message.
As mentioned in "Better ways of handling logging in containers " by Daniel Walsh:

One big problem with standard docker containers is that any service that writes messages to syslog or directly to the journal get dropped by default.
Docker does not record any logs unless the messages are written to STDIN/STDERR. There is no logging service running inside of the container to catch these messages.

So a simple echo should end up in syslog, as illustrated by the chentex/random-logger image.

From Docker for Mac / Log and Troubleshooting, you can check directly if you see any logs after your docker run:

To view Docker for Mac logs at the command line, type this command in a terminal window or your favorite shell.

$ syslog -k Sender Docker

2017:

Check the content of ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/log. Syslog driver was added in PR 11458

2022:

Brice mentions in the comments:

In Docker Desktop for macOs 4.x the logs are now here

$HOME/Library/Containers/com.docker.docker/Data/log/, 
# eg 
$HOME/Library/Containers/com.docker.docker/Data/log/vm/console.log
like image 71
VonC Avatar answered Oct 05 '22 23:10

VonC