How to Check Running Docker Containers on Linux Server - Complete Container Status Guide
Are you wondering how to check if Docker containers are running on your Linux server? Need to verify that your containerized applications like Nginx, MySQL, or Redis are up and running? This comprehensive guide shows you multiple methods...
How to Check Running Docker Containers on Linux Server - Complete Container Status Guide
Are you wondering how to check if Docker containers are running on your Linux server? Need to verify that your containerized applications like Nginx, MySQL, or Redis are up and running? This comprehensive guide shows you multiple methods to check running Docker containers, detect container failures automatically, monitor container health, and ensure service availability on your Linux server.
Why Checking Running Docker Containers Matters
Docker containers run critical applications and services on modern Linux servers. When containers stop unexpectedly or fail to start, your applications become unavailable, services can fail, and users experience downtime. Learning how to check running Docker containers helps you detect container failures immediately, ensure application availability, track container health, and troubleshoot container issues quickly. Regular container status checking prevents extended outages and helps you maintain high availability for your containerized infrastructure.
Method 1: List Running Containers with docker ps
The docker ps command is the primary tool for checking running Docker containers on Linux servers. This command provides quick access to container status and information.
Basic Container Listing
To see all running containers:
# List all running containers
docker ps
# List all containers including stopped
docker ps -a
# List containers with full command output
docker ps --no-trunc
# List containers with specific format
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
The docker ps command shows container ID, image, command, creation time, status, ports, and names by default.
Detailed Container Information
To get more detailed information about containers:
# Show containers with custom format
docker ps --format "{{.Names}}: {{.Status}} ({{.Image}})"
# Show containers with sizes
docker ps -s
# Show containers with labels
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Label \"com.example.version\"}}"
# Show containers with network information
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Networks}}"
Filter Running Containers
To show specific containers:
# Show containers by name pattern
docker ps --filter "name=nginx"
# Show containers by status
docker ps --filter "status=running"
# Show containers by image
docker ps --filter "image=nginx:latest"
# Show containers by label
docker ps --filter "label=environment=production"
Method 2: Check Container Status with docker inspect
The docker inspect command provides detailed information about containers, including their current state and health status.
Inspect Container Details
To get detailed container information:
# Inspect specific container
docker inspect container-name
# Inspect container state only
docker inspect --format='{{.State.Status}}' container-name
# Inspect container health status
docker inspect --format='{{.State.Health.Status}}' container-name
# Inspect container restart count
docker inspect --format='{{.RestartCount}}' container-name
Verify Container is Running
To check if a container is actually running:
# Check if container is running
docker inspect --format='{{.State.Running}}' container-name
# Check container exit code
docker inspect --format='{{.State.ExitCode}}' container-name
# Check container started at
docker inspect --format='{{.State.StartedAt}}' container-name
# Check container finished at (if stopped)
docker inspect --format='{{.State.FinishedAt}}' container-name
Method 3: Check Container Resource Usage
The docker stats command shows real-time resource usage for running containers, helping verify containers are functioning properly.
View Container Statistics
To see container resource usage:
# Show real-time stats for all containers
docker stats
# Show stats without streaming (one snapshot)
docker stats --no-stream
# Show stats for specific containers
docker stats container1 container2
# Show stats with custom format
docker stats --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}"
Monitor Container Performance
To track container resource consumption:
# Show CPU and memory usage
docker stats --no-stream --format "{{.Name}}: CPU {{.CPUPerc}}, Memory {{.MemUsage}}"
# Show container network I/O
docker stats --no-stream --format "{{.Name}}: Network {{.NetIO}}"
# Show container block I/O
docker stats --no-stream --format "{{.Name}}: Block {{.BlockIO}}"
Method 4: Check Container Logs
Container logs help verify containers are running correctly and identify issues.
View Container Logs
To see container logs:
# Show container logs
docker logs container-name
# Show last 100 log lines
docker logs --tail 100 container-name
# Follow container logs
docker logs -f container-name
# Show logs with timestamps
docker logs -t container-name
# Show logs since specific time
docker logs --since "2024-01-01T00:00:00" container-name
Verify Container Activity
To check if containers are actively processing:
# Show recent log activity
docker logs --tail 50 container-name
# Check for errors in logs
docker logs container-name 2>&1 | grep -i error
# Monitor logs for activity
docker logs -f container-name | grep -v "^$"
Method 5: Automated Container Status Monitoring with Zuzia.app
Manually checking running Docker containers works for occasional audits, but for production Linux servers, you need automated monitoring that alerts you when containers stop or fail. Zuzia.app provides comprehensive container status monitoring through scheduled command execution.
Setting Up Automated Container Monitoring
-
Add Scheduled Task in Zuzia.app Dashboard
- Navigate to your server in Zuzia.app
- Click "Add Scheduled Task"
- Choose "Command Execution" as the task type
-
Configure Container Check Command
- Enter command:
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Image}}" - Set execution frequency: Every 15 minutes for active monitoring
- Configure alert conditions: Alert when expected containers are not running
- Set up comparison with previous runs to detect changes
- Enter command:
-
Set Up Notifications
- Choose notification channels (email, webhook, Slack, etc.)
- Configure alert thresholds (e.g., alert if critical container stops)
- Set up escalation rules for critical containers
- Configure different alert levels for different container types
Monitor Specific Containers
For mission-critical containers, create dedicated monitoring tasks:
# Check specific critical containers
docker ps --filter "name=nginx" --filter "name=mysql" --filter "name=redis"
# Check containers by label
docker ps --filter "label=critical=true"
# Count running containers
docker ps -q | wc -l
# Verify expected containers are running
EXPECTED="nginx mysql redis"
for container in $EXPECTED; do
docker ps --format "{{.Names}}" | grep -q "^${container}$" || echo "Container $container is not running"
done
Zuzia.app stores all command outputs in its database, allowing you to track container status over time, identify containers that frequently restart, and detect container failures before they cause extended outages.
Method 6: Advanced Container Status Checking
Beyond basic checks, you can use advanced techniques to verify container status more effectively.
Count Containers by Status
To get container counts:
# Count running containers
docker ps -q | wc -l
# Count stopped containers
docker ps -a -f "status=exited" -q | wc -l
# Count containers by status
docker ps -a --format "{{.State}}" | sort | uniq -c
# Count containers per image
docker ps -a --format "{{.Image}}" | sort | uniq -c
Check Container Health Status
To verify container health:
# Show containers with health status
docker ps --format "table {{.Names}}\t{{.Status}}" | grep -i health
# Check health status for specific container
docker inspect --format='{{json .State.Health}}' container-name | jq
# List unhealthy containers
docker ps --format "{{.Names}}: {{.Status}}" | grep -i unhealthy
# Check health check results
docker inspect --format='{{.State.Health.Status}}' container-name
Detect Container Issues
To identify containers with problems:
# Show containers that restarted recently
docker ps -a --format "table {{.Names}}\t{{.Status}}\t{{.RestartCount}}" | grep -E "Restarting|restarted"
# Show containers with high restart count
docker ps -a --format "{{.Names}}: {{.RestartCount}} restarts" | awk -F: '$2 > 5'
# Check containers that exited with errors
docker ps -a --filter "status=exited" --format "{{.Names}}: Exit Code {{.State.ExitCode}}"
Real-World Use Cases for Container Status Checking
Application Availability Verification
For application servers, verify critical application containers:
# Check web application containers
docker ps --filter "name=webapp" --filter "name=api"
# Check database containers
docker ps --filter "name=mysql" --filter "name=postgres"
# Check cache containers
docker ps --filter "name=redis" --filter "name=memcached"
# Verify all application containers are running
docker ps --format "{{.Names}}" | grep -E "webapp|api|worker" | wc -l
Container Failure Detection
For failure detection, identify stopped or failed containers:
# List stopped containers
docker ps -a --filter "status=exited"
# List containers that exited with errors
docker ps -a --filter "status=exited" --format "{{.Names}}: Exit Code {{.State.ExitCode}}"
# Check containers that crashed
docker ps -a --format "{{.Names}}: {{.Status}}" | grep -i "exited\|dead"
Container Health Monitoring
For health monitoring, check container health status:
# Show containers with health checks
docker ps --format "table {{.Names}}\t{{.Status}}" | grep -i health
# Check unhealthy containers
docker ps --format "{{.Names}}: {{.Status}}" | grep -i unhealthy
# Verify container health endpoints (if available)
for container in $(docker ps --format "{{.Names}}"); do
HEALTH=$(docker inspect --format='{{.State.Health.Status}}' $container 2>/dev/null)
echo "$container: $HEALTH"
done
Best Practices for Container Status Checking
1. Check Containers Regularly
Check running containers every 15-30 minutes for active monitoring, and more frequently (every 5 minutes) for critical containers. This allows you to detect failures immediately and respond quickly. Use Zuzia.app automated monitoring to check containers continuously without manual intervention.
2. Focus on Critical Containers
While checking all containers is important, prioritize critical containers that impact your infrastructure: web servers, databases, application services, and monitoring tools. Create dedicated monitoring tasks for these containers with more frequent checks and immediate alerts.
3. Monitor Container Health Checks
If containers have health checks configured, monitor health status separately. Health checks provide more detailed information about container state than basic running status. Set up alerts for unhealthy containers to detect issues before containers crash.
4. Track Container Restart Frequency
Monitor container restart counts over time to identify containers that restart frequently. Containers that restart repeatedly might indicate configuration issues, resource constraints, or application problems. Use Zuzia.app's historical data to track restart patterns and identify root causes.
5. Document Expected Containers
Maintain documentation about expected containers. Document which containers should be running, their images, and their purposes. Update documentation when container configurations change.
Troubleshooting Common Container Issues
Container Not Running
If a container is not running:
# Check container status
docker ps -a | grep container-name
# Check container logs
docker logs container-name
# Check container exit code
docker inspect --format='{{.State.ExitCode}}' container-name
# Check container restart policy
docker inspect --format='{{.HostConfig.RestartPolicy.Name}}' container-name
Container Shows as Running But Not Working
If a container shows as running but isn't functioning:
# Check container health status
docker inspect --format='{{json .State.Health}}' container-name
# Check container logs for errors
docker logs --tail 100 container-name | grep -i error
# Check container resource usage
docker stats --no-stream container-name
# Test container connectivity (if applicable)
docker exec container-name curl -f http://localhost/health || echo "Container not responding"
Container Keeps Restarting
If a container keeps restarting:
# Check restart count
docker inspect --format='{{.RestartCount}}' container-name
# View recent logs
docker logs --tail 100 container-name
# Check container health
docker inspect --format='{{json .State.Health}}' container-name
# Check resource limits
docker inspect --format='{{.HostConfig.Memory}}' container-name
FAQ: Common Questions About Checking Running Docker Containers
How often should I check running Docker containers on my Linux server?
We recommend checking running containers every 15-30 minutes for active monitoring, and every 5 minutes for critical containers. This allows you to detect failures immediately and respond quickly. Use Zuzia.app automated monitoring to check containers continuously without manual intervention.
What should I do when a container stops or is not running?
When a container stops, first check the container logs using docker logs container-name to understand why it stopped. Then check the container exit code with docker inspect --format='{{.State.ExitCode}}' container-name. If the container should be running, restart it with docker start container-name. Investigate the root cause (application errors, resource constraints, configuration issues) before restarting to prevent repeated failures.
Can I check specific containers instead of all containers?
Yes, you can check specific containers using docker ps --filter "name=container-name" or by creating separate monitoring tasks in Zuzia.app for each critical container. This allows you to set different alert thresholds and notification channels for different container types. Checking specific containers also reduces system load compared to checking all containers.
How do I see why a container stopped or failed?
Use docker logs container-name to view container logs and identify error messages or failure reasons. Check the container exit code with docker inspect --format='{{.State.ExitCode}}' container-name - non-zero exit codes indicate errors. Check container health status with docker inspect --format='{{json .State.Health}}' container-name if health checks are configured.
What's the difference between docker ps and docker ps -a?
The docker ps command shows only running containers, while docker ps -a shows all containers including stopped ones. Use docker ps for quick checks of running containers, and docker ps -a when you need to see stopped containers or check container history.
Can I see container resource usage when checking status?
Yes, use docker stats --no-stream to see resource usage for all running containers, or docker stats container-name for a specific container. Resource usage helps verify containers are functioning properly and identify performance issues. Monitor CPU, memory, network, and disk I/O to ensure containers have adequate resources.
Does Zuzia.app track container status history and patterns?
Yes, Zuzia.app stores all command outputs in its database, allowing you to track container status over time and identify patterns. You can view historical data to see which containers stop most frequently, when containers restart, and how often containers need to be restarted manually. This helps you identify root causes and prevent recurring container failures.