0
0
Dockerdevops~30 mins

Centralized logging setup in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Centralized logging setup
📖 Scenario: You are managing multiple Docker containers running different applications. To keep track of all logs in one place, you want to set up a centralized logging system using Docker's built-in logging drivers.This helps you easily monitor and troubleshoot your applications without checking each container separately.
🎯 Goal: Build a simple Docker Compose setup with two containers that send their logs to a centralized logging container using the json-file logging driver. You will configure the logging options and verify the logs are collected centrally.
📋 What You'll Learn
Create a Docker Compose file with two application containers named app1 and app2.
Add a centralized logging container named logcollector.
Configure app1 and app2 to use the json-file logging driver with a max file size of 10m.
Print the logging configuration of app1 to verify the setup.
💡 Why This Matters
🌍 Real World
Centralized logging helps developers and operators monitor multiple containers easily, improving troubleshooting and system reliability.
💼 Career
Understanding Docker logging drivers and centralized log collection is essential for DevOps roles managing containerized applications.
Progress0 / 4 steps
1
Create Docker Compose services
Create a Docker Compose file named docker-compose.yml with two services: app1 and app2. Both should use the alpine image and run the command sh -c "while true; do echo Hello from app1; sleep 5; done" for app1 and sh -c "while true; do echo Hello from app2; sleep 5; done" for app2.
Docker
Need a hint?

Define two services under services: with the exact names app1 and app2. Use the alpine image and the given commands.

2
Add centralized logging container
Add a third service named logcollector to the docker-compose.yml. Use the busybox image and run the command sh -c "tail -f /var/log/app.log".
Docker
Need a hint?

Add a new service named logcollector with the busybox image and the specified tail command.

3
Configure logging driver for app containers
Configure both app1 and app2 services in docker-compose.yml to use the json-file logging driver with the option max-size: 10m.
Docker
Need a hint?

Under each app service, add a logging section with driver: json-file and options: max-size: 10m.

4
Print logging configuration of app1
Run the command docker inspect --format='{{json .HostConfig.LogConfig}}' $(docker-compose ps -q app1) in your terminal to print the logging configuration of the app1 container.
Docker
Need a hint?

Use docker inspect with --format='{{json .HostConfig.LogConfig}}' and the container ID of app1 from docker-compose ps -q app1.