Docker Compose — up, down, ps

1 minute read

These three commands form the core lifecycle of every Compose stack.

docker compose up

Start all services:

docker compose up              # Foreground (Ctrl+C to stop)
docker compose up -d           # Detached (background)
docker compose up --build      # Rebuild images before starting
docker compose up --force-recreate   # Recreate even if unchanged
docker compose up api db       # Start specific services only

Common Flags

Flag Purpose
-d Run in background
--build Rebuild images first
--force-recreate Force container recreation
--no-deps Don’t start dependencies
--remove-orphans Remove services not in compose file
--wait Wait for services to be healthy
--scale api=3 Run 3 instances of api

docker compose down

Stop and remove containers, networks:

docker compose down            # Stop and remove containers + networks
docker compose down -v         # Also remove volumes
docker compose down --rmi all  # Also remove images
docker compose down --rmi local  # Remove only locally-built images

Cleanup Levels

Command Removes
down Containers + networks
down -v + named volumes
down --rmi local + locally-built images
down --rmi all + all images used
down -v --rmi all Everything

docker compose ps

List running containers:

docker compose ps              # Running services
docker compose ps -a           # All (including stopped)
docker compose ps --format json  # JSON output
docker compose ps --services   # Service names only

Example Output

NAME          IMAGE         COMMAND       SERVICE   STATUS          PORTS
myapp-api-1   myapi:latest  "node ..."    api       Up 5 minutes    0.0.0.0:3000->3000/tcp
myapp-db-1    postgres:16   "docker..."   db        Up 5 minutes (healthy)   5432/tcp
myapp-web-1   nginx:alpine  "/dock..."    web       Up 5 minutes    0.0.0.0:80->80/tcp

stop, start, restart

docker compose stop            # Stop without removing
docker compose start           # Start previously stopped
docker compose restart         # Stop + start
docker compose restart api     # Restart specific service

Lifecycle Flow

create ──▶ up ──▶ running ──▶ stop ──▶ start ──▶ running
                      │                               │
                      └────── restart ────────────────┘
                      │
                      └──▶ down (removes everything)

Summary

Command Effect
up -d Create and start (background)
down Stop and remove
down -v Remove volumes too
ps List containers
stop Stop (keep containers)
start Resume stopped containers
restart Stop + start

Quick Reference

Item Detail
up -d Start detached
up –build Rebuild then start
down Stop and remove containers
down -v Also remove volumes
ps List running services
ps -a Include stopped services
stop/start Pause/resume without removing