1
3

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のイメージもコンテナもぜーんぶきれいに消してやり直したい時のコマンド

Posted at

Dockerいまだに慣れておらず初期開発環境構築のたびに何度も作り直してます。。
何度も作り直してると同じような名前のものばかりになるし一掃してしまいたくなることがよくありその時のコマンドをメモしておきます。

すべてのコンテナを停止

terminal
PS C:\Users\607> docker stop $(docker ps -aq)

停止したコンテナIDが出力されます

出力ログ
b900982a522d

すべてのネットワークを停止

terminal
> docker system prune

有効なネットワーク数分ズラズラとログが出力されます

terminal
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - all dangling build cache

Are you sure you want to continue? [y/N] y
Deleted Containers:
b900982a522d3b706885a57cd3ae04f1e5e72266a230a9ed5d746fd67e9fb98c

Deleted Images:
deleted: sha256:917f7b2666d566d786c7a87d88c3a526ae73328b58883dd03ac56ac0c80892b1
deleted: sha256:0b7df1af6007d6a4579dae5458781967fe4f7541c25c50db585956d05d183cf0
deleted: sha256:042d7491666f0d7608fe6cfe54f7231818c3346c8f169a3edae50be677a4ba83
...

Deleted build cache objects:
reiknr169oxc59f9jy7hzp7tc
4olrdqcoqku9didqkquggjepb
ulylctcvpthkhx6l9erfchllz
...
Total reclaimed space: 1.574GB

イメージをすべて削除

terminal
> docker rmi -f $(docker images -aq)

イメージ数分長い何かが出力されます

出力ログ
Untagged: vueapp:0.0.1
Deleted: sha256:a66b8502954033b2e9052e5b2a25dabc3a5d6d03de1ca2dd4c5c0e3b47ce260f
Untagged: httpd:latest
Untagged: httpd@sha256:b82fb56847fcbcca9f8f162a3232acb4a302af96b1b2af1c4c3ac45ef0c9b968
Deleted: sha256:3dd970e6b110c8cbcec63e05a91e3cefd23c76a780fcb78c33979153f044b2d4
Deleted: sha256:92ed257f355234f3e6173699f2ef99363a5babec07a6b9178b2b1afb57214c55
Deleted: sha256:b57fd9052964b1f8e16ba5e3785018ba52de527c6aba686bb3845581ca4b77d7
...

これで何度も失敗しても心機一転キレイにやり直せます。

1
3
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
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?