DCubes
Docker module

Lesson 11

Compose up

A compose.yaml, services, docker compose up and down — one file instead of a pile of flags.

beginner35 minRun on your machine

What you will be able to do

  • Write a Compose file with one service
  • Start and stop it with docker compose up and down
  • Read compose ps and logs

Why this matters for DE and AI

A data stack is several processes: a database, a job, maybe a UI. Remembering every -p and -e is how teammates drift. A Compose file is the recipe for this laptop: services, ports, volumes, env. docker compose up is the shared start command.

Concepts

Filename: compose.yaml (or docker-compose.yml — both work). We use compose.yaml.

Minimum shape:

services:
  web:
    image: nginx:1.27-alpine
    ports:
      - "18080:80"
  • services — named containers. The name (web) becomes the hostname on the Compose network.
  • image — what to run. (You can use build: instead; we did that with a Dockerfile already.)
  • ports — the same HOST:CONTAINER as -p.

Commands — always from the directory that contains the file:

Command What it does
docker compose up Create and start; logs in the foreground
docker compose up -d Detached
docker compose ps Status of this project
docker compose logs Logs for the project
docker compose logs -f web Follow one service
docker compose down Stop and remove containers and the default network

down does not delete named volumes unless you pass -v. We will use -v only when we mean to wipe a database.

Project name defaults to the directory name. Two folders with their own compose.yaml do not clash.

There is no version: key at the top anymore. Skip it.

Practice on your machine

mkdir -p ~/dcubes/docker-lab/compose-web
cd ~/dcubes/docker-lab/compose-web
cat > compose.yaml << 'EOF'
services:
  web:
    image: nginx:1.27-alpine
    ports:
      - "18080:80"
EOF
docker compose up -d
docker compose ps

What you should see: service web, status running / Up, port 18080->80.

curl -sS -o /dev/null -w '%{http_code}\n' http://127.0.0.1:18080
docker compose logs --tail=20

200 from curl. Logs should mention nginx starting.

docker compose down
docker compose ps

What you should see: down removes the container. ps is empty. curl to 18080 should fail.

Foreground mode (optional): docker compose up without -d streams logs; Ctrl + C stops the stack. Prefer -d when you still need the terminal for curl.

Common mistakes

  • Running compose from the wrong folder. It looks for compose.yaml in .. cd first, or docker compose -f path/to/compose.yaml.
  • docker-compose (hyphen) vs docker compose (space). This module uses the space (v2 plugin).
  • up when the host port is busy. Another process (or a leftover container) owns 18080. down the old project, or change the host port.

Next

Compose a data stack — Postgres, a job, healthchecks, and depends_on.