Docker Compose and
Multi-Container
Applications
Managing multiple containers effortlessly!
Objectives of this Module:
• Understand what Docker Compose is and why it is used.
• Learn how to define multi-container applications.
• Set up a docker-compose.yml file.
• Run and manage multiple containers using Docker Compose.
• Activity: Build a Flask app with a database using Docker Compose.
What is Docker Compose?
Definition: Docker Compose is a tool for defining and running multi-container
applications.
Why Use Docker Compose?
Simplifies managing multiple services.
Uses a single configuration file (docker-compose.yml).
Automates networking and container lifecycle management.
Installing Docker Compose
Steps to Install:
Verify Docker installation (docker --version).
Check if Docker Compose is included (docker-compose --version).
If not installed, follow official installation instructions.
Writing a docker-compose.yml File
Key Sections:
version: Defines Docker
Compose version.
services: Lists all app
components.
depends_on: Ensures
dependent services start first.
Running a Multi-Container App
Steps:
Navigate to project directory.
Run docker-compose up --build to build and start containers.
Check logs with docker-compose logs.
Stop containers with docker-compose down.
Tip: Use -d flag to run in detached mode.
Managing and Debugging Containers
Common Commands:
docker-compose ps: List running services.
docker-compose restart <service>: Restart a service.
docker-compose exec <service> bash: Access service shell.
Tip: Always check logs for errors.
Activity
Task: Convert your Dockerized Flask app into a multi-container setup.
Create a docker-compose.yml file.
Add a PostgreSQL or SQLite database service.
Run the app and test connectivity.
Submission: Submit the docker-compose.yml file and a screenshot of running
services.
Summary
Key Takeaways:
• Docker Compose simplifies multi-container management.
• docker-compose.yml defines service configurations.
• Containers can be easily started, stopped, and managed.
Next Steps: Learn about exposing applications to the internet using Ngrok in Module
4.
Docker Compose and
Multi-Container
Applications
Managing multiple containers effortlessly!