Practice Exercise 2
Practice Exercise 2: Docker Container Monitoring Exercise
Objective: This exercise aims to equip interns with practical knowledge in monitoring Docker containers using various commands and tools. Upon completion, interns should be able to answer the question: "How do you monitor containers?"
Prerequisites:
- Basic understanding/review of Docker commands.
- Access to a Linux host with Docker installed.
Exercise Steps:
Part 1: Basic Docker Container Monitoring
Step 1: List Running Containers
- Open a terminal on the Linux host.
- Use the
docker ps
command to list running containers. - Observe container IDs, names, and other relevant information.
Step 2: Container Resource Monitoring
- Use the
docker stats
command to display live container resource usage. - Observe CPU usage, memory usage, and network activity.
Step 3: Container Logs
- Use the
docker logs <container_id>
command to access container logs. - Identify log entries related to container events and activities.
Part 2: Inspecting Docker Containers
Step 1: Container Inspection
- Use the
docker inspect <container_id>
command to obtain detailed information about a specific container. - Examine the JSON output and identify key container attributes.
Step 2: Analyzing Container Metrics
- Extract specific metrics (e.g., CPU, memory) from the
docker inspect
output. - Understand how to use this information for monitoring.
Part 3: Docker Compose Monitoring
Step 1: Compose Services
- If not already done, create a Docker Compose file with multiple services.
- Use
docker-compose up -d
to start the services.
Step 2: Monitoring Compose Services
- Use the
docker-compose ps
command to list running services. - Explore monitoring options for the entire Compose environment.
Part 4: Creating a Docker Monitoring Script
Step 1: Write a Monitoring Script
- Write a shell script that incorporates Docker commands used in the exercise.
- The script should provide an overview of running containers and their resource usage.
-
The script will do the following:
-
It will monitor a specific host resource.
-
Will have an exit status.
-
Will notify through email.
-
Will have to log every time the script runs.
-
The script will run every 5 minutes.
-