DEV Community

Yash Sonawane
Yash Sonawane

Posted on

Docker Series: Episode 21 β€” Docker Logging & Monitoring Essentials πŸ“Š

Welcome back to the Docker series! Now that we’ve covered security, volumes, networking, and orchestration, it’s time to ensure your containers are healthy and observable. In production, logging and monitoring are key to detecting issues early and maintaining uptime.


πŸ”Ή Why Logging & Monitoring Matter

  • Containers are ephemeral β€” logs inside them can vanish if the container stops.
  • Monitoring helps track CPU, memory, network usage, and container health.
  • Alerts help prevent downtime and detect anomalies.

πŸ”Ή Container Logging Basics

  • Docker captures logs for each container by default.
  • View logs:
docker logs <container_name>
Enter fullscreen mode Exit fullscreen mode
  • Follow logs in real-time:
docker logs -f <container_name>
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή Using Logging Drivers

Docker supports multiple logging drivers:

  • json-file (default)
  • syslog
  • journald
  • fluentd
  • awslogs
  • splunk

Example: Using syslog driver

docker run -d --log-driver=syslog nginx
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή Monitoring Containers

1. Docker Stats

docker stats
Enter fullscreen mode Exit fullscreen mode

Shows CPU, memory, network, and disk usage in real-time.

2. Third-Party Tools

  • Prometheus + Grafana β†’ Metrics collection + visualization.
  • cAdvisor β†’ Resource usage per container.
  • ELK Stack (Elasticsearch, Logstash, Kibana) β†’ Centralized logs.

πŸ”Ή Logging in Docker Compose

services:
  web:
    image: nginx
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"
Enter fullscreen mode Exit fullscreen mode
  • Rotate logs automatically to prevent disk overflow.

πŸ”Ή Best Practices

  • Always centralize logs for production.
  • Monitor container metrics continuously.
  • Set up alerts for high CPU, memory, or container crashes.
  • Rotate logs to avoid disk space issues.

πŸ”Ή Hands-On Challenge

  1. Run a container and view logs using docker logs.
  2. Set up a json-file logging driver with rotation.
  3. Install cAdvisor and observe container metrics.

βœ… Next Episode: Episode 22 β€” Docker Networking Advanced: Multi-Host & Overlay Networks β€” take your networking skills to production-level setups.

Top comments (0)