0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

初心者向け基本のdocker-composeコマンド

Last updated at Posted at 2020-07-12

build(イメージをビルドする)

$ docker-compose build
docker-compose.ymlファイルを元にイメージをビルドする

up(コンテナを開始する)

$ docker-compose up -d
コンテナがなければ作成し、コンテナを開始する。
create + start。

-dをつけるとバックグラウンドで起動して実行したまま。
-dをつけないとコマンド終了時にコンテナは停止する。

$ docker-compose up --build -d
--build で強制ビルドする。
設定ファイル等の編集後、既存のイメージを使われると変更が反映されないので、再度ビルドさせたい場合に使う。

stop(コンテナを停止する)

docker-compose stop
コンテナを削除せずに実行を停止します。 docker-compose startで再度開始できます。

down(イメージ等を削除する)

$ docker-compose down
今あるdockerイメージとかを削除する。
コンテナを停止し、 up で作成したコンテナ・ネットワーク・ボリューム・イメージを削除します。デフォルトではコンテナとネットワークのみ削除します。

ps(コンテナの一覧を出力する)

$ docker-compose ps
コンテナの一覧を出力する。
起動しているかなどの状態がわかる。

images(イメージの一覧を出力する)

docker-compose images
作成したコンテナが使用するイメージの一覧を表示します。
イメージのIDなどがわかる。

exec(コマンドを実行する)

$ docker-compose exec
サービスに対する任意のコマンドを実行する。

コンテナの中に入る
例:$ docker-compose exec web bash

おまけ

# exit
コンテナから出る

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?