LoginSignup
1
2

More than 5 years have passed since last update.

docker のコンテナを名前指定してまとめて削除する

Posted at

docker を勉強しはじめてすぐのぼくは、image を作ったり消したり、container を作ったり消したりします。

そして、気づいたら、用もないコンテナの残骸が溜まっていました。:kissing:

(こんなことはめったに起こることじゃないかもしれないのですが。...)

docker ps -a で、コンテナ一覧を出すと以下のようになっていました。

スクリーンショット 2017-02-04 18.30.54.png

このコンテナのうち、NAMES のプレフィックスが dockerstudy_ のものだけまとめて削除したくなりました。

--filter を使います。以下のように絞り込めます。

$ docker ps -a --filter name=dockerstudy_
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                         PORTS               NAMES
5c8a1e50795d        08cd3696b3ea        "rails s"                28 minutes ago      Exited (1) 28 minutes ago                          dockerstudy_web_run_7
1ba5d18092a1        08cd3696b3ea        "rails db:create"        29 minutes ago      Exited (0) 29 minutes ago                          dockerstudy_web_run_6
a65e6d3bf762        08cd3696b3ea        "bundle exec rails..."   29 minutes ago      Exited (1) 29 minutes ago                          dockerstudy_web_run_5
e98a77eba0b8        08cd3696b3ea        "rails db:create"        About an hour ago   Exited (0) About an hour ago                       dockerstudy_web_run_4
7b6d813ff696        08cd3696b3ea        "bundle exec rails..."   About an hour ago   Exited (1) 30 minutes ago                          dockerstudy_web_1
8b7e95531148        dff0928dc81a        "rails db:create"        About an hour ago   Exited (1) About an hour ago                       dockerstudy_web_run_3
d5f4b576a22e        6049a99885c0        "rails db:create"        About an hour ago   Exited (7) About an hour ago                       dockerstudy_web_run_2
d749860ac076        6049a99885c0        "rails new . --for..."   About an hour ago   Exited (0) About an hour ago                       dockerstudy_web_run_1
c28f1ce26c08        postgres            "/docker-entrypoin..."   About an hour ago   Exited (0) 26 minutes ago                          dockerstudy_db_1

よって、-q を用いて、以下のコマンドで満たされました。

name指定でまとめて削除
$ docker rm `docker ps -aq --filter name=dockerstudy_`

以上、ありがとうございました。:slight_smile:

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