How to use Docker Compose: install Docker, write compose file, up/down, logs, first web+DB stack
Install Compose, define a web+Postgres stack, and manage it with up, down, and logs.
You need a web tier and PostgreSQL on your laptop without fighting host package versions. Docker Compose describes multi-container apps in docker-compose.yml and drives them with one CLI.
Searchers looking for Docker Compose install docker-compose.yml up down logs web database stack usually need Docker + Compose installed, a valid compose file, up/down workflow, logs for debugging, and a working web + database example. Steps follow docs.docker.com.
Who Compose is for
Full-stack / backend devs
Run API + DB locally the same way teammates do; avoid manual install drift.
Ops-curious engineers
Practice up/down/logs/ps before Kubernetes or cloud PaaS.
Workshop authors
One compose file bootstraps nginx + Postgres; reset with down -v when needed.
Install Docker and the Compose plugin
- 1
macOS / Windows: Docker Desktop
Download from
https://docs.docker.com/desktop/(Docker Hub download links redirect there). Install, start Docker Desktop, wait until the engine reports running. Compose V2 ships asdocker compose. - 2
Linux: Docker Engine + compose plugin
Follow
https://docs.docker.com/engine/install/for your distro, then install the Compose plugin perhttps://docs.docker.com/compose/install/linux/(package name oftendocker-compose-plugin). - 3
Verify CLI
Run
docker --versionanddocker compose version. If only hyphenateddocker-composeexists, prefer upgrading to the plugin; legacy binary behavior differs slightly. - 4
Permissions (Linux)
Without sudo, add your user to the
dockergroup per official post-install steps, then log out/in. Do not chmod/var/run/docker.sockto world-writable.
Write your first docker-compose.yml (web + PostgreSQL)
Create a project folder with docker-compose.yml (filename also accepted: compose.yaml). Example: nginx on port 8080 and PostgreSQL 16 with a named volume:
services:
web:
image: nginx:alpine
ports:
- "8080:80"
volumes:
- ./html:/usr/share/nginx/html:ro
depends_on:
- db
db:
image: postgres:16-alpine
environment:
POSTGRES_USER: app
POSTGRES_PASSWORD: devpass
POSTGRES_DB: appdb
volumes:
- db_data:/var/lib/postgresql/data
volumes:
db_data:Put a simple html/index.html on the host. Never commit real passwords; use .env for local secrets and add .env to .gitignore (see Docker docs on env files).
Start, stop, and tail logs
| Command | Action | When |
|---|---|---|
docker compose up -d | Start detached | First bring-up |
docker compose ps | Status / ports | Confirm mapping |
docker compose logs -f web | Follow logs | Debug startup |
docker compose stop | Stop containers | Pause without removing |
docker compose down | Remove containers/network | Clean shutdown |
docker compose pull | Refresh images | Before upgrades |
Verify the web + database stack
- 1
HTTP
Open
http://localhost:8080— nginx should serve yourindex.html. - 2
Database
docker compose exec db psql -U app -d appdb -c '\dt'checks Postgres inside the container. - 3
Rebuild after edits
If you add a
build:section later, usedocker compose up -d --build.
Compose orchestrates containers on one Docker host; it is not a cloud substitute. Backups, TLS, and scaling live in platform-specific docs.
Once the stack runs locally, open a browser room from the wbroom homepage for whiteboard or voice sync — create and join a room.
Questions worth checking
Compose V2 vs legacy docker-compose?
Modern installs ship docker compose (V2 plugin). Hyphenated docker-compose is the older standalone binary; confirm with docker compose version.
Does docker compose down wipe data?
Named volumes (e.g. db_data) survive a normal down. Use docker compose down -v only when you intend to reset dev data.
Port already in use?
Change the host side in ports (e.g. 8080:80) or inspect with docker compose ps / lsof.
Is this compose file production-ready?
This guide targets local learning: default passwords, no TLS, no backups. Production needs secrets, healthchecks, limits, and pinned image tags per Docker docs.