Docker Compose
July 9, 2025
Compose defines and runs multiple containers together from one YAML file.
Commands
docker compose -f filename up # start all services
docker compose -f filename down # stop and remove them
docker compose build # build all images
docker compose push # push all images to a registry
docker compose(space, new) vsdocker-compose(hyphen, old) — both work; use whichever is installed.
If the file is the default docker-compose.yml in the current folder, you can
drop -f filename and just run docker compose up.
Example compose file
version: "3.8"
services:
backend:
build:
context: ./backend
dockerfile: Dockerfile
image: <dockerhub-username>/<name>-backend:latest
ports:
- "5000:5000"
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
image: <dockerhub-username>/<name>-frontend:latest
ports:
- "8080:80"
depends_on:
- backend
context— folder to build from;dockerfile— which Dockerfile to use.image— the tag the built image gets (needed to push to Docker Hub).ports— HOST:CONTAINER (openlocalhost:8080in the browser).depends_on— startbackendbeforefrontend.
See also [[docker-hub-push-images]] and [[docker-multi-container-app]].