Simple Configuration
Define multiple application components in a single configuration file.
Learn how to build and manage multi-container applications using Docker Compose. Understand compose.yaml, services, networks, volumes, environment variables, and the most important Docker Compose commands.
Application Stack
Introduction
Docker Compose is designed for applications that use multiple containers. Instead of manually running each container with separate Docker commands, you can define your application configuration in a Compose file.
For example, a typical application might contain a frontend, backend API, database, and caching service. Docker Compose allows these services to be defined and managed together.
The Compose configuration can also define networking, storage, environment variables, and other settings required by your application.
Your First Compose File
This example defines a web application and a database service running together.
services:
web:
build: .
ports:
- "3000:3000"
environment:
DATABASE_HOST: database
depends_on:
- database
database:
image: postgres:16
environment:
POSTGRES_DB: appdb
POSTGRES_USER: appuser
POSTGRES_PASSWORD: password
volumes:
- postgres-data:/var/lib/postgresql/data
volumes:
postgres-data:Why Docker Compose
Docker Compose provides a structured way to configure and manage services that work together as part of an application.
Define multiple application components in a single configuration file.
Run services such as web applications, APIs, databases, and caches together.
Use the same Compose configuration across development, testing, and other workflows.
Start, stop, rebuild, inspect, and monitor your application stack with Docker Compose commands.
Core Concepts
These concepts will help you understand how multi-container applications are structured and managed using Docker Compose.
Understand how Docker Compose helps define and run applications that use multiple containers.
Learn how the Compose YAML file defines the services and configuration required by your application.
Understand how each application component, such as a frontend, backend, database, or cache, can be defined as a service.
Learn how to use the build configuration to create a Docker image from a Dockerfile.
Learn how services can use existing container images from registries.
Understand how services communicate with each other through Docker networks.
Learn how named volumes and mounts can be used to store data outside the lifecycle of individual containers.
Learn how to configure application settings and environment-specific values.
Use Docker Compose commands to start, stop, rebuild, inspect, and manage your application.
Learn how Docker Compose can organize applications that contain multiple connected services.
Essential Commands
These commands are commonly used to start, stop, inspect, and troubleshoot Docker Compose applications.
docker compose upCreate and start the services defined in your Compose configuration.
docker compose up -dStart the services in detached mode so they continue running in the background.
docker compose downStop and remove the containers and resources created for the application stack.
docker compose psDisplay the current status of services in the Compose project.
docker compose logs -fFollow and view log output from the running services.
docker compose exec web shRun an interactive shell or command inside a running service container.
Skills You Will Learn
Build the foundation required to work with multi-container Docker applications.
Learning Roadmap
Follow this process to define and run your first multi-container application.
Start with one or more applications or services that you want to run together.
Create a Compose configuration file in your project directory.
Configure the application components that make up your stack.
Add ports, environment variables, and other service configuration.
Configure communication between services and persistent storage where required.
Use docker compose up to create and start the services defined in your configuration.
What's Next?
After learning Docker Compose, continue exploring Docker images, containers, networking, storage, and DevOps workflows.
Start Building
Create your compose.yaml file, define your services, and start your complete application stack with Docker Compose.