docker compose

Start a whole app (web, database…) from one docker-compose.yml file with a single command.

>_ Try it: a simulated Linux, right here
Loading the terminal…

Examples

  • docker compose up -d
  • docker compose ps
  • curl localhost:3000
  • docker compose logs
  • docker compose down
  • docker compose up -d --build

How it works

docker compose reads docker-compose.yml, which lists the services of an app (for example a web server and its database), and starts them all together, on their own network.

docker compose up -d builds what needs building, creates the network and starts every service in the background. docker compose down stops and removes them again, in one go.

Syntax

docker compose [OPTIONS] COMMAND

Options

OptionWhat it does
up -dstart every service in the background
pslist the services and their status
logsshow what the services printed
downstop and remove the services and their network
--buildrebuild the images first (with up)

Good to know

  • Services find each other by name on their network: the web service reaches the database as db, not localhost.
  • The old docker-compose (with a dash) is the same tool, version 1. New setups use docker compose.