8
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 の未使用コンテナとイメージを削除

Posted at

Docker で未使用のコンテナとイメージを削除するありがちなスクリプトです。

なんかいっつもやり方を忘れるのでシェルスクリプトでまとめたのですが、それすらどこに置いたか忘れがちなので自分用にメモしておきます。

#!/bin/bash
nonuse=`echo $(docker ps -aq | awk 'END{print NR}')`
if [ $nonuse != '0' ] ; then
  docker rm `docker ps -aq`
fi
noneimage=`echo $(docker images | awk '/^<none>/' | awk 'END{print NR}')`
if [ $noneimage != '0' ] ; then
  docker rmi $(docker images | awk '/^<none>/ { print $3 }')
fi

開発中は古いイメージがどんどん溜まっていくのでこういったスクリプトで一気に消してスッキリしましょう。

8
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
8
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?