Compose
Compose describes an application made of several containers (services, volumes, networks) in a single compose.yaml.
Example
Section titled “Example”services: db: image: postgres:17 environment: POSTGRES_PASSWORD: secret volumes: - pgdata:/var/lib/postgresql/data restart: unless-stopped
api: build: . ports: - "8000:8000" environment: DB_HOST: db depends_on: - db restart: unless-stopped
volumes: pgdata:Compose creates a network for the project automatically, so api reaches the database at host db.
Commands
Section titled “Commands”docker compose up -d # create and start everything in the backgrounddocker compose up -d --build # rebuild images firstdocker compose ps # state of the servicesdocker compose logs -f api # follow the logs of one servicedocker compose exec api sh # shell inside a servicedocker compose restart apidocker compose stop # stop without removingdocker compose down # stop and remove containers and the networkdocker compose down -v # … and the volumes too (deletes the data!)docker compose pull # download newer versions of the imagesdocker compose config # show the final configuration, with variables resolvedWith Podman, use podman compose with the same subcommands. It delegates to podman-compose or docker-compose, whichever is installed.
Variables
Section titled “Variables”Compose reads a .env file next to compose.yaml:
POSTGRES_PASSWORD=secretenvironment: POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}Keep .env out of Git if it holds passwords.