docker compose up -dCreate and start everything in the background.
Compose v2 (the docker compose plugin). The file is compose.yaml; docker-compose.yml still works.
14 entries
docker compose up -dCreate and start everything in the background.
docker compose down
docker compose down -vStop and remove containers (and volumes with -v).
docker compose ps
docker compose logs -f apiStatus; follow one service’s logs.
docker compose exec api sh
docker compose run --rm api npm testShell in a running service; one-off command.
docker compose build --no-cache
docker compose up -d --buildRebuild images.
docker compose pull
docker compose restart apiUpdate images; restart one service.
docker compose configPrint the resolved file (checks syntax and variables).
services:
api:
build: .
ports:
- "8000:8000"
env_file: .env
depends_on:
db:
condition: service_healthy
db:
image: postgres:16
environment:
POSTGRES_PASSWORD: example
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
retries: 5
volumes:
pgdata:API + Postgres with a healthcheck so the API waits for the DB.
restart: unless-stoppedRestart policy.
volumes:
- ./src:/app/srcBind-mount code for live reload in development.
environment:
DATABASE_URL: postgres://postgres:example@db:5432/postgresServices reach each other by service name (db).
profiles: ["debug"]Only started with --profile debug.
docker compose -f compose.yaml -f compose.prod.yaml up -dLayer files; later ones override earlier ones.
# compose.override.yaml is loaded automaticallyPut dev-only settings there.
docker compose (with a space) is Compose v2, built into the Docker CLI. The old Python docker-compose v1 is deprecated; the file format is the same.
Only if you use condition: service_healthy together with a healthcheck on the dependency. Plain depends_on only waits for the container to start.
Use environment: for inline values, env_file: for a file, and ${VAR} interpolation which reads from your shell or a .env file next to compose.yaml.