Docker Compose Workflow
Understanding Docker Compose
Docker Compose is a tool for defining and running multi-container Docker applications. It uses YAML files to configure application services, networks, and volumes, enabling complex application architectures with simple configuration.
graph TD
A[Docker Compose YAML] --> B[Service Configuration]
B --> C[Container Orchestration]
B --> D[Network Setup]
B --> E[Volume Management]
Installation on Ubuntu 22.04
## Install Docker Compose
sudo apt update
sudo apt install docker-compose-plugin
## Verify installation
docker compose version
Docker Compose Configuration File
A typical docker-compose.yml
structure includes services, networks, and volumes:
version: '3.8'
services:
web:
image: nginx:latest
ports:
- "8080:80"
database:
image: postgres:13
environment:
POSTGRES_PASSWORD: mysecretpassword
volumes:
- postgres-data:/var/lib/postgresql/data
volumes:
postgres-data:
Key Docker Compose Commands
Command |
Description |
docker compose up |
Create and start containers |
docker compose down |
Stop and remove containers |
docker compose ps |
List containers |
docker compose logs |
View container logs |
docker compose build |
Build or rebuild services |
Multi-Container Application Example
version: '3.8'
services:
frontend:
build: ./frontend
ports:
- "3000:3000"
backend:
build: ./backend
ports:
- "5000:5000"
depends_on:
- database
database:
image: mongo:latest
volumes:
- mongodb_data:/data/db
volumes:
mongodb_data:
Advanced Configuration Techniques
services:
web:
restart: always
environment:
- DEBUG=True
networks:
- app_network
deploy:
replicas: 3
update_config:
parallelism: 1
networks:
app_network:
driver: bridge