Logging with Docker
faisal@druva.com
The Problem
- Logging is a pain
- Docker: single process/container
- App already logs to syslog
- Consolidating for all containers
- Network logging for archival, analysis etc
Application stack
- Single logger daemon running on host
- Each app logs to /dev/log
- syslog configured to log locally and/or send to network logger
running without Docker
Application Stack
- One or more apps now run in a container
- Container filesystem is constrained
- What about logging?
running under Docker
Logging with Docker
- Depends on your container architecture
- Potential solutions:
- Run log daemon on docker host
- Run log daemon inside each container
- Run single log daemon in a separate container for all other containers
- For non-syslogging apps, use syslog driver when launching container
Logger on docker host
Logger on docker host..
- Set up logger daemon on host as usual
- Map /dev/log on host to /dev/log on all containers when launching
- Log post-processing/analysis on host machine
The Good
- Setup straightforward
- Easy to test
- Handle logging for all containers including docker daemon
- Containers need no change
The Bad
- Tied to host
- Deploying at scale
- Managing at scale
Logger in each container
Logger in each container..
- Logger launched before actual process in each container
- Optionally use fat containers like phusion/baseimage
- /dev/log created by each logger instance prior to actual process startup
- Unless logging to n/w, logger target folder needs to be mapped into each container
The Good
- Completely self-contained
- Easy to setup/test
- Logger failure limited to container
- Great for standalone containers
The Bad
- Container custom-built
- Extra process overhead
- Cannot log docker daemon logs
- Upgrading logger requires container rebuild
- Logging to single file painful
Single Logger Container
Single Logging Container
- Logging container started first
- /some/host/path mapped to /dev for this container
- /some/host/log/output mapped to /var/log
- Each app container launched with /some/host/path/log mapped to /dev/log
The Good
- Deploy at scale
- Upgrading logger easy
- Just another container to run
The Bad
- Cannot log docker daemon logs
Docker logging driver
- Great for non-syslog compliant apps
- Supports:
- json-file: default
- syslog
- journald (systemd)
- gelf (Graylog Extended Log Format)
- fluentd
- awslogs (AWS cloudwatch logs)
Docker syslog driver
- Great feature for non-syslog capable apps
- Leverage existing logger
- Usable with logger running on host or in a single container:
$docker run --log-opt syslog-address==unix://path ...
- Or on a remote host:
$docker run --log-opt syslog-address=[tcp|udp]://host:port ...
DockerLogging
By faisyl
DockerLogging
Logging and how to do it on docker containers
- 612