Skip to content
Statusthreat center ›
← All guides
DevOps · 9 min · 2025-05-20

Monitoring Docker Containers: Best Practices

Track container health, resource usage, and logs. Best practices for Docker monitoring in production environments.

> For people who run servers

Written in 2025 for ServerGuard
Product statements in this guide may be out of date. For what works today, see the ServerGuard page and the capabilities.

Why Docker Monitoring is Different

Docker containers are ephemeral — they start, stop, and get replaced frequently. Traditional server monitoring tools don't always work well with containers. You need monitoring that understands the container lifecycle.

Key Metrics for Containers

Resource Usage per Container

# Built-in Docker stats
docker stats --no-stream

# Formatted output
docker stats --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}"

Container Health

  • Status: Running, Stopped, Restarting, Dead
  • Restart count: High restart counts indicate instability
  • Uptime: How long since last restart
  • Health checks: Custom health check results

Image & Configuration

  • Image version: Track which image version is deployed
  • Port mappings: Verify correct port configuration
  • Volume mounts: Ensure data persistence
  • Network: Container network connections

Setting Up Docker Monitoring with ServerGuard

ServerGuard's agent automatically detects running Docker containers and monitors them:

# Install the agent - Docker monitoring included
curl -sSL https://safeavio.com/install.sh | sudo bash

# Verify Docker access
sudo docker ps

What Gets Monitored

  • Container count (running, stopped, total)
  • Per-container CPU and memory usage
  • Network I/O per container
  • Container logs (aggregated and searchable)
  • Image pull status and updates
  • Health check results

Best Practices

1. Set Resource Limits

Never run containers without resource limits in production:

# docker-compose.yml
services:
  web:
    image: nginx
    deploy:
      resources:
        limits:
          cpus: '1.0'
          memory: 512M
        reservations:
          cpus: '0.25'
          memory: 128M

2. Use Health Checks

HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
  CMD curl -f http://localhost/health || exit 1

3. Centralize Logs

# Docker daemon logging config
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}

4. Monitor the Docker Daemon

The host running Docker needs monitoring too:

  • Docker daemon CPU/memory usage
  • Disk space (images can consume lots of space)
  • Docker socket availability
  • Container networking health

5. Clean Up Unused Resources

# Remove unused containers, images, networks
docker system prune -a --volumes

# Check disk usage
docker system df

Alerting Strategy

AlertThresholdPriority
Container stoppedAny critical containerHigh
Restart loop>3 restarts in 5minHigh
Memory >90% of limitPer containerMedium
CPU >80% sustainedPer containerMedium
Disk space >85%Docker hostHigh
Health check failing3 consecutiveHigh

Conclusion

Docker monitoring requires understanding both the container layer and the host layer. Use resource limits, health checks, and centralized monitoring to keep your containerized applications running smoothly. ServerGuard provides out-of-the-box Docker monitoring so you can focus on building, not babysitting containers.