docker compose up

パッケージと実行環境

書き方

docker compose up [-d] [--build] [<service>...]

compose.yamlに書かれたサービスを一まとまりとして立ち上げます。ハイフン付きのdocker-composeは引退したv1で今はdocker composeプラグインであり、既にあるコンテナは--buildや--force-recreateがなければそのまま再利用されます。

よく使うオプション

オプション意味
-dstart in the background
--buildrebuild images before starting
--force-recreatereplace containers even if nothing changed
--remove-orphansclean up containers of services you deleted
--waitreturn only once healthchecks pass
--scale <svc>=<n>run n copies of one service

docker compose up -d

starts every service in compose.yaml in the background

docker compose up --build web

rebuilds and starts one service

docker compose down -v

stops everything and deletes the named volumes, database data included

何をどこに入れるかが問題です。このプロジェクトの中か、マシン全体かを先に決めてください。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. docker compose up は何をしますか。

compose.yamlに書かれたサービスを一まとまりとして立ち上げます。ハイフン付きのdocker-composeは引退したv1で今はdocker composeプラグインであり、既にあるコンテナは--buildや--force-recreateがなければそのまま再利用されます。

Q. どう打ちますか。

docker compose up [-d] [--build] [<service>...] — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは6個です。全部は man docker にあります。このコマンドはパッケージと実行環境の仲間です。

関連するコマンド

man ページ: man docker-compose-up