Verified5 commandsAI-assisted

Compose, Networking & Volumes

Verified against Docker 29.1.5 (Compose v2, built in), flags verified via `docker <cmd> --help`, 2026-08-20 · official docs

Running multi-container stacks with Compose, and the networking/volume primitives underneath them.

Compose — starting and stopping a stack#

docker compose up -d                                 # start everything defined in compose.yaml, detached
docker compose up -d --build                          # rebuild images first
docker compose down                                    # stop and remove containers + default network
docker compose down -v                                 # also remove named volumes (destroys persisted data)
docker compose stop                                     # stop without removing containers

docker compose (space, no hyphen) is the current, built-in form — the old standalone docker-compose binary is deprecated. down -v is destructive: it deletes any named volumes the stack owns, including database data, so it's not the default even though it's tempting to reach for when "cleaning up."

Compose — inspecting a running stack#

docker compose ps
docker compose logs -f
docker compose logs -f my-service                       # logs for one service only
docker compose exec my-service /bin/bash
docker compose top

Compose — rebuilding and scaling#

docker compose build my-service
docker compose up -d --force-recreate my-service         # recreate even if config hasn't changed
docker compose up -d --scale worker=3                      # run 3 replicas of the worker service

Networks#

docker network ls
docker network create my-network --driver bridge --subnet 172.20.0.0/16
docker network connect my-network my-container
docker network inspect my-network                          # see connected containers + IPs
docker network rm my-network

Compose creates its own bridge network per project automatically, and every service in that compose file can reach every other one by service name (DNS resolution built in) — you rarely need docker network create by hand unless you're connecting containers started outside Compose.

Volumes#

docker volume ls
docker volume create my-data
docker volume inspect my-data
docker run -v my-data:/var/lib/postgresql/data postgres:16   # named volume — Docker-managed storage
docker run -v ./local-dir:/app/data myapp:latest              # bind mount — a real host path
docker volume rm my-data
docker volume prune                                            # remove all volumes not used by any container

A named volume (my-data:/path) is managed by Docker and portable across containers; a bind mount (./local-dir:/path) ties a container directly to a specific path on the host filesystem — reach for a named volume for anything that needs to survive a container being recreated but doesn't need to be human-editable from the host.