Skip to main content

Container Status Monitoring

Monitor the status of your Docker containers to ensure the application is running properly.
1

Check running containers

Use the docker ps command to view all running containers:
docker ps
Expected output:
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                    NAMES
abc123def456   ...       "node server/index.js"   5 minutes ago   Up 5 minutes   0.0.0.0:5000->5000/tcp   miniproject
The container name miniproject is defined in docker-compose.yml:7. Verify the STATUS column shows “Up” to confirm the container is running.
2

View all containers (including stopped)

To see both running and stopped containers:
docker ps -a
This helps identify if the container has stopped unexpectedly.

Application Logs

View real-time logs from the application container to monitor activity and debug issues.

View Container Logs

docker logs miniproject
Expected output:
✅ Server running on port 5000

Follow Logs in Real-Time

To monitor logs as they’re generated:
docker logs -f miniproject
Press Ctrl+C to stop following logs. The -f flag is similar to tail -f and continuously streams new log entries.

View Last N Lines

To see only the most recent log entries:
docker logs --tail 50 miniproject

Logs with Timestamps

Include timestamps for better debugging:
docker logs -t miniproject

Application Health Checks

Verify that your application is responding correctly to requests.

Test Backend Endpoint

Check if the Express server is responding on port 5000:
curl http://localhost:5000
Expected response:
Hello, This is from Mini project Deployment!
This endpoint is defined in server/index.js:7-9. A successful response confirms the backend is running and accessible.

Check Response Headers

View complete HTTP response including headers:
curl -I http://localhost:5000
Expected output:
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
...

Automated Health Check Script

Create a simple health check script:
health-check.sh
#!/bin/bash
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:5000)
if [ $RESPONSE -eq 200 ]; then
  echo "✅ Application is healthy"
else
  echo "❌ Application is unhealthy (HTTP $RESPONSE)"
fi
Make it executable and run:
chmod +x health-check.sh
./health-check.sh

Resource Monitoring

Monitor CPU, memory, and network usage of your containers.

Real-Time Resource Usage

docker stats miniproject
Expected output:
CONTAINER ID   NAME          CPU %     MEM USAGE / LIMIT     MEM %     NET I/O       BLOCK I/O   PIDS
abc123def456   miniproject   0.05%     45MiB / 7.775GiB     0.56%     2.5kB / 0B    0B / 0B     11
Monitor these metrics to identify performance issues:
  • CPU %: Should typically be low for this application
  • MEM USAGE: Node.js applications typically use 40-100MB for small apps
  • NET I/O: Increases with traffic

Resource Usage (One-Time)

For a single snapshot without continuous updates:
docker stats miniproject --no-stream

Monitor All Containers

View stats for all running containers:
docker stats

Jenkins Build Monitoring

Monitor Jenkins pipeline builds to ensure successful deployments.

Check Build Status

  1. Access Jenkins dashboard at http://localhost:8080 (or your Jenkins URL)
  2. Navigate to your pipeline job
  3. View the latest build status and console output

Pipeline Stages

The Jenkins pipeline defined in Jenkinsfile includes these stages:
1

Checkout

Clones the repository from GitHub (Jenkinsfile:7)
2

Build Docker Image

Builds the Docker image with tag react-express-app (Jenkinsfile:14)
3

Run Container

Stops old container and starts new one on port 5000 (Jenkinsfile:25)

Monitor Build Logs

Check Jenkins console output for:
  • Successful checkout from Git
  • Docker build completion
  • Container startup confirmation
  • Success message: “Deployment completed successfully!” (Jenkinsfile:33)
  • Failure message: “Build or deployment failed!” (Jenkinsfile:36)
If a build fails, check the Jenkins console output for error messages. Common issues include Docker daemon connectivity, port conflicts, or missing dependencies.

Container Inspection

Get detailed information about the container configuration.

Inspect Container

docker inspect miniproject
This returns JSON with complete container details including:
  • Network settings and IP address
  • Port mappings (5000:5000)
  • Environment variables
  • Mount points
  • Resource limits

View Specific Information

Extract specific fields using --format:
# Get container IP address
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' miniproject

# Get port mappings
docker inspect -f '{{.NetworkSettings.Ports}}' miniproject

# Get container status
docker inspect -f '{{.State.Status}}' miniproject

Docker Compose Monitoring

When using docker-compose, use these commands:

View Service Status

docker-compose ps

View Service Logs

docker-compose logs app

Follow Compose Logs

docker-compose logs -f app
The service name app is defined in docker-compose.yml:3. This corresponds to the miniproject container.

Monitoring Best Practices

Configure Docker health checks in your Dockerfile or docker-compose.yml to automatically monitor application health:
docker-compose.yml
services:
  app:
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:5000"]
      interval: 30s
      timeout: 10s
      retries: 3
Prevent logs from consuming too much disk space by configuring log rotation:
docker run -d \
  --log-driver json-file \
  --log-opt max-size=10m \
  --log-opt max-file=3 \
  miniproject
Regularly check Docker disk usage to prevent space issues:
docker system df
Clean up unused resources:
docker system prune -a
Prevent containers from consuming excessive resources:
docker-compose.yml
services:
  app:
    deploy:
      resources:
        limits:
          cpus: '0.5'
          memory: 512M

Build docs developers (and LLMs) love