Here are five different tasks designed for a middle-level Python developer to practice Docker Compose. These tasks will help you gain hands-on experience with container orchestration, networking, and integration of multiple services using Docker Compose.
Task 1: Build a Multi-Container Flask Application
Objective: Create a Flask-based web application that interacts with a PostgreSQL database.
-
Requirements:
- Use Docker Compose to define two services: one for the Flask app and another for the PostgreSQL database.
- The Flask app should expose an API endpoint (e.g.,
/users) that retrieves data from the PostgreSQL database.
- Populate the database with some initial data (e.g., a
users table with dummy entries).
- Ensure proper environment variable management for database credentials (use
.env files).
-
Learning Goals:
- Understand how to link containers using Docker Compose.
- Learn how to manage database migrations and environment variables in a containerized setup.
-
Deliverables:
- A
docker-compose.yml file.
- Flask app code and database schema.
- Instructions to run the application.
Task 2: Deploy a Python-Based Message Queue System
Objective: Set up a message queue system using RabbitMQ and a Python producer-consumer architecture.
-
Requirements:
- Use Docker Compose to define three services:
- A RabbitMQ service for message brokering.
- A Python producer service that sends messages to the queue.
- A Python consumer service that processes messages from the queue.
- Implement a simple use case, such as sending and processing "email notifications."
- Ensure logs are generated for both producer and consumer activities.
-
Learning Goals:
- Understand asynchronous communication between services.
- Practice scaling services (e.g., running multiple consumers).
-
Deliverables:
- A
docker-compose.yml file.
- Producer and consumer Python scripts.
- Logs showing successful message processing.
Task 3: Containerize a Machine Learning Model Serving API
Objective: Serve a pre-trained machine learning model using a Python-based API and Redis for caching predictions.
-
Requirements:
- Use Docker Compose to define three services:
- A Python API service (e.g., FastAPI or Flask) that serves predictions from the model.
- A Redis service for caching frequently requested predictions.
- A worker service that periodically updates the cache.
- Use a simple pre-trained model (e.g., scikit-learn) for demonstration purposes.
- Ensure the API supports endpoints like
/predict and /cache.
-
Learning Goals:
- Learn how to integrate a machine learning model into a containerized application.
- Understand caching mechanisms and their benefits in API design.
-
Deliverables:
- A
docker-compose.yml file.
- Python scripts for the API, worker, and model inference.
- Demonstration of cached vs. uncached responses.
Task 4: Build a CI/CD Pipeline with Jenkins and Python
Objective: Automate testing and deployment of a Python application using Jenkins and Docker Compose.
-
Requirements:
- Use Docker Compose to define two services:
- A Jenkins service for continuous integration.
- A Python application service for testing and deployment.
- Configure Jenkins to:
- Run unit tests on the Python application.
- Build a Docker image if tests pass.
- Deploy the application using Docker Compose.
- Use a sample Python project with a few unit tests.
-
Learning Goals:
- Understand CI/CD workflows in a containerized environment.
- Learn how to integrate Jenkins with Docker Compose.
-
Deliverables:
- A
docker-compose.yml file.
- Jenkins configuration files (e.g.,
Jenkinsfile or pipeline script).
- Logs showing successful test execution and deployment.
Task 5: Create a Distributed Logging System
Objective: Implement a centralized logging system for multiple Python microservices.
-
Requirements:
- Use Docker Compose to define three services:
- Two Python microservices (e.g.,
service-a and service-b) that generate logs.
- An ELK stack (Elasticsearch, Logstash, Kibana) for log aggregation and visualization.
- Each microservice should send logs to Logstash via HTTP or TCP.
- Use Kibana to visualize logs (e.g., filter logs by service name or severity level).
-
Learning Goals:
- Learn how to centralize logs in a distributed system.
- Gain experience with the ELK stack for log management.
-
Deliverables:
- A
docker-compose.yml file.
- Python scripts for
service-a and service-b.
- Screenshots of Kibana dashboards showing aggregated logs.
Additional Notes:
- Each task is designed to build specific skills while reinforcing Docker Compose concepts.
- You can expand these tasks by adding features like health checks, monitoring (e.g., Prometheus/Grafana), or advanced networking configurations.
- Always document your work, including instructions for running the setup and any challenges faced during implementation.
By completing these tasks, you'll gain confidence in managing multi-container applications and integrating various tools and services using Docker Compose.