docker compose
Start a whole app (web, database…) from one docker-compose.yml file with a single command.
>_ Try it: a simulated Linux, right herenothing runs on your computer
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
| Option | What it does |
|---|---|
up -d | start every service in the background |
ps | list the services and their status |
logs | show what the services printed |
down | stop and remove the services and their network |
--build | rebuild 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, notlocalhost. - The old
docker-compose(with a dash) is the same tool, version 1. New setups usedocker compose.