SyntaxStudy
Sign Up
Docker Monitoring and Observability for Docker
Docker Beginner 1 min read

Monitoring and Observability for Docker

Observability for Dockerised applications requires collecting metrics, logs, and traces from containers. Docker exposes container metrics (CPU, memory, network, disk I/O) via docker stats and through the Docker API. Prometheus can scrape these metrics using cadvisor, which runs as a container and exports per-container resource metrics in Prometheus format. Grafana then visualises them on a dashboard. Centralised logging is essential when you have multiple containers on multiple hosts. The ELK stack (Elasticsearch, Logstash, Kibana) or Grafana Loki are popular choices. Configure the Docker logging driver to forward to Logstash or Loki. Applications should log JSON to stdout — the logging driver handles forwarding. Distributed tracing with OpenTelemetry instruments your application with spans that cross service boundaries. The OpenTelemetry collector runs as a container in the same Docker network, receives traces via OTLP, and exports to Jaeger, Tempo, or a managed service. Adding trace IDs to log entries links traces and logs, dramatically reducing mean-time-to-diagnose for production incidents.
Example
# compose.yaml - full observability stack
services:
  app:
    build: .
    environment:
      OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4317
      OTEL_SERVICE_NAME: myapp
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "5"

  cadvisor:
    image: gcr.io/cadvisor/cadvisor:latest
    volumes:
      - /:/rootfs:ro
      - /var/run:/var/run:ro
      - /sys:/sys:ro
      - /var/lib/docker/:/var/lib/docker:ro
    ports:
      - "8080:8080"

  prometheus:
    image: prom/prometheus:latest
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
    ports:
      - "9090:9090"

  grafana:
    image: grafana/grafana:latest
    ports:
      - "3001:3000"
    volumes:
      - grafana-data:/var/lib/grafana

  otel-collector:
    image: otel/opentelemetry-collector:latest
    volumes:
      - ./otel-config.yaml:/etc/otel-config.yaml:ro
    command: --config /etc/otel-config.yaml

volumes:
  grafana-data:

This is the last lesson in this section.

Create a free account to earn a certificate