How to monitor docker containers log from non-root user? How to monitor docker containers log from non-root user? docker docker

How to monitor docker containers log from non-root user?


logspout is another way to collect containerslogs. I'm not sure this is the best solution, but it is very interesting and consistent way to collect containers logs.

You just need to run logspout container. This container has a feature that send docker containers' logs to other syslog server. (or you can use HTTP api also. see repository)

# (172.17.42.1 is host ip address)$ docker run -v=/var/run/docker.sock:/tmp/docker.sock progrium/logspout syslog://172.17.42.1:5140

And fluentd that is running on host can handle these logs through syslog protocal. Below is td-agent.conf example. It receive logs from syslog protocal and send them to elasticsearch server. (check this example project)

<source>  type syslog  port 5140  bind 0.0.0.0  tag syslog.udp  format /^(?<time>.*?) (?<container_id>.*?) (?<container_name>.*?): (?<message>.*?)$/  time_format %Y-%m-%dT%H:%M:%S%z</source><match syslog.**>  index_name <ES_INDEX_NAME>  type_name <ES_TYPE_NAME>  type elasticsearch  host <ES_HOST>  port <ES_PORT>  flush_interval 3s</match>


As I discussed in detail in this answer that the OP never acknowledged whatsoever, I find the best approach is to configure the applications running within the container to log messages to syslog, and mount the host's syslog socket to the container.

docker run -v /dev/log:/dev/log ...

Downside of this approach is that if the syslog daemon on the host is restarted, the container will lose it's socket since the daemon recreates the socket at restart.

A fix for this would be to add another socket (in rsyslog this can be done using the imuxsock module). Create the additional socket in some known directory, then bind mount the directory instead of /dev/log directly. The additional socket will also be removed when rsyslog restarts, but will be recreated and available to the application in the directory following the restart.


One easy way to deal with this issue is to mount host's /sys/fs/cgroup into a Docker container that's running in_docker_metrics. See https://github.com/bdehamer/docker-librato