You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Real applications consist of multiple services — a web server, an API, a database, a cache, a message queue. Managing these with individual docker run commands is tedious and error-prone. Docker Compose lets you define and manage multi-container applications in a single YAML file.
Docker Compose is a tool for defining and running multi-container Docker applications. You describe your entire application stack in a docker-compose.yml (or compose.yaml) file, then use a single command to create and start everything.
# Start all services defined in docker-compose.yml
docker compose up -d
# Stop all services
docker compose down
# docker-compose.yml
services:
web:
image: nginx:alpine
ports:
- "8080:80"
depends_on:
- api
api:
build: ./api
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgres://user:pass@db:5432/mydb
depends_on:
- db
db:
image: postgres:16
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: mydb
volumes:
- db-data:/var/lib/postgresql/data
volumes:
db-data:
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.