Docker Compose explained
Compose describes one or more services in a YAML file. The following is a standalone tutorial example, not a copy of a production stack.
services:
demo-web:
image: nginx:stable-alpine
container_name: demo-web
restart: unless-stopped
ports:
- "8080:80"
volumes:
- ./site:/usr/share/nginx/html:ro
| Key | Meaning |
|---|---|
services | Container definitions |
image | Image to pull |
container_name | Human-friendly name |
restart | Restart policy |
ports | Host-to-container port mapping |
volumes | Bind mount or persistent storage |
:ro | Read-only mount |
Run the example
mkdir -p ~/compose-demo/site && cd ~/compose-demo
printf '<h1>It works!</h1>\n' > site/index.html
# Save the YAML above as compose.yml
docker compose config --quiet
docker compose up -d
docker compose ps
curl -I http://127.0.0.1:8080
Stop it with docker compose down. For production, pin tested image versions or digests rather than blindly updating every container.