6
7

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 5 years have passed since last update.

Dockerのコンテナをまとめて削除する

Last updated at Posted at 2015-11-13

(追記) 最近のバージョンのDockerでは、「prune」オプションが追加されましたので、お手軽に削除できますな。ついでに、imageもprune、systemもpruneできますね。

Stopしているコンテナをまとめて削除する。

$ docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y

確認不要なら、 -f オプションをつける。

$ docker container prune -f

Docker Versionが古い場合は、下記のコマンドで。

$ docker rm $(docker ps -aq)

ps コマンドの -q オプションで、コンテナIDのみを取得します。
-a オプションで、全てのコンテナ(止まっているコンテナも)を対象にします。
なお、動いているコンテナは、エラーになって削除できません。

-f オプションで、強制削除できます。

$ docker rm -f $(docker ps -aq)
6
7
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
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?