Modern applications seldom consist of a single process. Even a basic web application relies on several services: web servers, databases, caches, background workers, and message queues. Handling these components separately using basic Docker commands is prone to errors and hard to maintain.
This is where Docker Compose comes in.
Docker Compose enables developers to manage multiple container applications with a single configuration file and a handful of commands. Instead of manually creating containers, setting up networks, and mounting volumes, everything is defined in a single place.

What this tutorial covers:
So, let’s get started.
Docker Compose is a utility for defining, configuring, and running multi-container Docker applications. Docker Compose uses a YAML file (docker-compose.yml) to define application services, their dependencies, networks, and storage.
Single-host container orchestration explained.
Docker Compose is designed for a single host machine. Unlike Kubernetes, it is intended for:
When Docker Compose is used in real projects
Purpose of the Compose file
The docker-compose.yml file contains the following information:
It serves as the central source of truth for your application stack.
Why YAML is used
YAML is a human-readable, structured, and declarative language, making it the best choice for infrastructure configuration.
What a service is
A service is a single container configuration. Each service launches a container from an image or Dockerfile.
One service vs multiple services
Default networks
Docker Compose will automatically create a default bridge network for all services in a project.
Service-to-service communication
Services can communicate with each other using service names and hostnames, without needing to specify ports.
Persistent data handling
Volumes are used to handle data outside the lifetime of containers so that data isn’t lost when containers are restarted.
Named vs anonymous volumes
Inline variables
Variables can be defined inline in the docker-compose.yml file.
.env file usage
The .env file is used to provide a secure way to configure your application without hardcoding values.
What a Docker Compose project is
A project is a collection of containers, networks, and volumes launched from a Compose file.
Project name and isolation
Each project is isolated by name so that there are no conflicts when running multiple stacks.
All the above actions can be performed with a single command.
Docker Compose in modern DevOps.
Yes, Docker Compose is still an essential part of:
Docker Compose vs Kubernetes (when to use each)
Real-world relevance in 2026
Docker Compose is still widely used and supported, especially for development.
Core differences explained
Use cases for each
When Docker Compose is the better choice
Anytime your app depends on more than one thing. Docker Compose is the winner.
docker compose versionIf installed, you’ll see the version number.
If not, install Docker Desktop or Docker Compose manually.
Example project structure:
my-app/
├── docker-compose.yml
├── app/
│ └── index.js
└── DockerfileThis structure helps your services be organised and easy to maintain.
Example docker-compose.yml:
version: "3.9"
services:
web:
image: nginx
ports:
- "8080:80"This defines:
docker compose upRun in detached mode:
docker compose up -dDocker Compose will pull the images, create the networks, and start the containers.
Common commands:
docker compose ps
docker compose logs
docker compose restart
docker compose stop
docker compose down
docker compose downDeletes containers and networks (and optionally volumes).
Profiles enable the ability to turn the service on or off depending on the environment.
Examples include:
The project name defaults to the directory name.
Override it:
docker compose -p myproject upThis enables multiple isolated stacks on a single host.
Using .env file:
DB_HOST=database
DB_PORT=5432In docker-compose.yml:
environment:
- DB_HOST=${DB_HOST}Environment variables improve security and flexibility.
Docker Compose supports dependencies:
depends_on:
- dbFor production, combine this with health checks.
Example 1: Web Application + Database (Node.js + PostgreSQL)
version: "3.9"
services:
app:
image: node:18
container_name: node_app
working_dir: /usr/src/app
volumes:
- ./app:/usr/src/app
command: npm start
ports:
- "3000:3000"
depends_on:
- db
db:
image: postgres:15
container_name: postgres_db
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: secret
POSTGRES_DB: mydb
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:What’s happening in this example?
Great for backend development and testing.
Example 2: Nginx Reverse Proxy + Backend Service
Internal networking allows systems to be connected without exposing their backend publicly; instead, they’re managed through nginx to route requests to other backends.
version: "3.9"
services:
backend:
image: node:18
container_name: backend_service
ports:
- "4000"
nginx:
image: nginx: latest
container_name: nginx_proxy
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
depends_on:
- backend
This architecture is a good fit for any API-based application.
Example 3: Production-Ready Docker Compose Setup
version: "3.9"
services:
web:
image: nginx: latest
restart: always
ports:
- "80:80"
deploy:
resources:
limits:
memory: 512M
api:
image: my-api: latest
restart: unless-stopped
environment:
APP_ENV: production
Best practices that can be used in this setup include:
For small and medium production infrastructure only.
| Command | Purpose |
|---|---|
docker compose up | Start services |
docker compose down | Stop and remove the stack |
docker compose logs | View logs |
docker compose exec | Run the command in the container |
docker compose build | Build images |
docker compose pull | Pull images |
Yes, there is no cost to use Docker Compose, as it is part of the Docker open-source software and is free to the public.
Yes, you can use Docker Compose to run small- to medium-sized production installations, internal production tools, and controlled deployments. However, if you have large enterprise-class installations, you may need to explore Kubernetes to run at scale.
No, Docker Compose will continue to be maintained and will remain a popular method of creating applications in the future.
Docker Compose is generally a good place to start, as it is easier to understand the concept of multi-container applications. Once you feel comfortable with the concepts behind Docker, you can then move on to learning how to use Kubernetes to orchestrate multi-container applications on a large scale.
For anyone developing containerised applications, Docker Compose is an important tool. It is the in-between of basic Docker usage and a full orchestration platform.
If you work with multi-service applications, Docker Compose isn’t just a nice-to-have; it’s essential.
After this, continue to learn Docker networking and optimise Docker files, and look to learn about Kubernetes at some point as a primary orchestration platform.
Comments