Docker Container Monitoring in Production: What to Track
Docker Container Monitoring in Production: What to Track
Docker container monitoring is essential for maintaining reliable containerized applications in production. This comprehensive guide covers everything you need to know about monitoring Docker containers, including resource usage, health checks, log management, and automated monitoring strategies.
For related container topics, see Kubernetes Monitoring. For troubleshooting container issues, see Docker Container Crash Restart Loop.
Why Docker Container Monitoring Matters
Container monitoring helps you understand container resource consumption, detect performance issues, ensure container health, and maintain reliable containerized applications. Without proper monitoring, containers can consume excessive resources, crash unexpectedly, or fail silently.
Effective container monitoring enables you to:
- Track container resource usage (CPU, memory, disk, network)
- Monitor container health and restart status
- Detect container crashes and restart loops
- Optimize container resource allocation
- Plan capacity upgrades based on actual usage
- Ensure container availability and reliability
Key Container Metrics to Monitor
Resource Metrics
- CPU Usage: Container CPU consumption percentage
- Memory Usage: Container memory consumption and limits
- Disk I/O: Container disk read/write operations
- Network I/O: Container network traffic (RX/TX)
Health Metrics
- Container Status: Running, stopped, restarting, paused
- Restart Count: Number of container restarts
- Uptime: Container uptime duration
- Health Check Status: Container health check results
Performance Metrics
- Container Start Time: Time to start container
- Log Volume: Amount of logs generated
- Error Rate: Container error frequency
Method 1: Monitor Containers with Docker Commands
Check Container Status
# List all containers
docker ps -a
# List running containers
docker ps
# Show container details
docker inspect <container_id>
# Check container stats
docker stats
# Monitor specific container
docker stats <container_id>
Monitor Container Resources
# Real-time container resource usage
docker stats --no-stream
# Container resource usage over time
docker stats --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}"
# Check container memory usage
docker stats --format "{{.Container}}: {{.MemUsage}}"
Check Container Logs
# View container logs
docker logs <container_id>
# Follow container logs
docker logs -f <container_id>
# View last 100 log lines
docker logs --tail 100 <container_id>
# View logs with timestamps
docker logs -t <container_id>
Method 2: Monitor Container Health
Check Container Health Status
# Check container health
docker inspect --format='{{.State.Health.Status}}' <container_id>
# View health check details
docker inspect --format='{{json .State.Health}}' <container_id> | jq
# Check restart count
docker inspect --format='{{.RestartCount}}' <container_id>
Monitor Container Restarts
# List containers with restart count
docker ps -a --format "table {{.Names}}\t{{.Status}}\t{{.RestartCount}}"
# Find containers that restarted recently
docker ps -a --filter "status=restarting"
# Check container exit codes
docker ps -a --format "table {{.Names}}\t{{.Status}}\t{{.ExitCode}}"
Method 3: Automated Container Monitoring with Zuzia.app
Manual checks work while you are looking. To keep running them without you, Zuzia uses its agent and scheduled tasks.
How it works in Zuzia
- Install the Zuzia agent on the server with one command. CPU, RAM, disk, load and network metrics start reporting on their own, with alerts on a threshold, on drift from the server's normal, or on a disk fill-up forecast.
- Save the commands from this guide as a scheduled task and choose how often it runs, from every minute to once a year. The agent runs it on every host you pick.
- If a command fails, you get an alert right away by email, Slack, Discord, push (through your Pushover account) or SMS (through your Vonage account).
- The output of every run is kept, so you can look back at what changed. On paid plans, AI can read the output and alert you only when it spots a problem.
Setting it up
- Add the server in the Zuzia dashboard and install the agent.
- Create a scheduled task with the check commands below, then choose the hosts and how often it runs.
- Choose your notification channels. Turn on maintenance mode during planned work so it doesn't trigger alerts.
Best Practices for Docker Container Monitoring
1. Monitor Container Resources Continuously
- Track CPU and memory usage for all containers
- Monitor disk I/O for container operations
- Track network usage per container
- Alert when resource usage exceeds thresholds
2. Implement Health Checks
- Configure health checks for all containers
- Monitor health check status continuously
- Alert on health check failures
- Review health check logs regularly
3. Monitor Container Restarts
- Track restart counts for all containers
- Alert on excessive restarts
- Investigate root causes of restarts
- Monitor container exit codes
4. Manage Container Logs
- Monitor log volume per container
- Set up log rotation to prevent disk issues
- Review error logs regularly
- Use centralized logging solutions
5. Optimize Resource Allocation
- Set appropriate resource limits for containers
- Monitor resource usage vs limits
- Adjust limits based on actual usage
- Prevent resource exhaustion
Troubleshooting Container Issues
Step 1: Identify Container Problems
When containers have issues:
Check Container Status:
- Review container status with
docker ps -a - Check restart counts
- Review container exit codes
- Review container status with
Monitor Resource Usage:
- Check CPU and memory usage with
docker stats - Review resource limits vs usage
- Identify resource-intensive containers
- Check CPU and memory usage with
Review Container Logs:
- Check container logs for errors
- Review health check logs
- Analyze log patterns
Step 2: Resolve Container Issues
Based on investigation:
Fix Resource Issues:
- Adjust container resource limits
- Optimize container resource usage
- Scale containers if needed
Fix Health Check Failures:
- Review health check configuration
- Fix application issues causing failures
- Update health check scripts
Resolve Restart Loops:
- Investigate root causes
- Fix application bugs
- Update container configuration
FAQ: Common Questions About Docker Container Monitoring
How often should I check container status?
For production containers, continuous automated monitoring is essential. Zuzia.app can execute container monitoring commands every few minutes, storing historical data and alerting you when issues are detected.
What is considered high container resource usage?
High resource usage depends on your container's limits and workload. Generally, CPU usage above 80% or memory usage above 90% of limits indicates potential issues and should be investigated.
How do I monitor containers across multiple servers?
Zuzia.app allows you to monitor containers across multiple servers from one centralized dashboard. Each server executes container monitoring commands independently, and all results are stored for centralized analysis.
What should I do when a container keeps restarting?
When a container keeps restarting, check container logs for errors, review health check status, investigate resource exhaustion, and fix application bugs or configuration issues causing the restarts.
How can I prevent container resource exhaustion?
Prevent resource exhaustion by setting appropriate resource limits, monitoring resource usage continuously, optimizing container resource consumption, and scaling containers when needed.
Related guides, recipes, and problems
Related guides
guides--monitoring-container-orchestration-kubernetes.mdguides--server-resource-monitoring-complete-guide.mdguides--monitoring-application-performance-linux.md
Related recipes
recipes--monitor-docker-container-resource-usage.mdrecipes--how-to-check-docker-containers-running.mdrecipes--check-docker-security-configuration-audit.md
Related problems
problems--docker-container-crash-restart-loop.mdproblems--high-memory-usage-server.mdproblems--service-keeps-stopping-restarting.md