🎓 A1Learner
🔍
0 of 50 lessons completed

What Is Docker Compose?

Docker Compose runs a whole multi-container app from one YAML file. The file names the services, their images, their ports and their volumes, and one command starts them all.

A tiny compose file

Two services: a web server and a database, in one file.

services:
  web:
    image: nginx:1.27-alpine
    ports:
      - "8111:80"
  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_PASSWORD: secret

Start it all

One command starts every service in the file.

docker compose up -d

Example

docker compose version

Key points

  • Compose: the tool that runs many containers from one file.
  • Service: one container in the file, with its image and settings.
  • The file is called compose.yaml, written in YAML.
  • Use docker compose up to start every service, and docker compose down to stop them.
  • Use Compose when an app needs a database beside it, or any second container.

In this example, one command shows the Compose version on the machine. The version proves Compose is installed beside Docker. The next lessons use it to run real apps.

Note

Compose is for one machine. Many machines need Swarm or Kubernetes.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

What does a compose.yaml file describe?