ゴミのように溜まったDockerイメージを一括削除するには

以下のようにすればいい

```
$ docker images | grep none | awk '{print $3}' | xargs docker rmi
```


# 解説
イメージのリビルドを繰り返して以下のように `<none>` となったイメージを一括削除したい

```
$ docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
rails6mysql_web           latest              e15aac16592a        39 minutes ago      949MB
<none>                    <none>              16b17b901c2c        54 minutes ago      949MB
<none>                    <none>              72637ae4b155        About an hour ago   949MB
<none>                    <none>              1311ff40521a        About an hour ago   791MB
<none>                    <none>              2950365d3727        2 hours ago         767MB
<none>                    <none>              a065e3343191        2 hours ago         566MB
<none>                    <none>              fb1e4481b7ee        2 hours ago         566MB
<none>                    <none>              7a8f553d442d        2 hours ago         566MB
<none>                    <none>              adb679d80383        4 hours ago         566MB
<none>                    <none>              485abdefc669        4 hours ago         565MB
docker-rails6-mysql_web   latest              f2b8555fb528        5 days ago          
                                  :
                                  :
```

`none`を含む行をgrep して

```
$ docker images | grep none
<none>                    <none>              16b17b901c2c        About an hour ago   949MB
<none>                    <none>              72637ae4b155        About an hour ago   949MB
<none>                    <none>              1311ff40521a        2 hours ago         791MB
<none>                    <none>              2950365d3727        2 hours ago         767MB
<none>                    <none>              a065e3343191        2 hours ago         566MB
<none>                    <none>              fb1e4481b7ee        2 hours ago         566MB
<none>                    <none>              7a8f553d442d        2 hours ago         566MB
<none>                    <none>              adb679d80383        4 hours ago         566MB
<none>                    <none>              485abdefc669        5 hours ago         565MB
```

`IMAGE ID` のフィールド(3カラム目)を切り出して

```
$ docker images | grep none | awk '{print $3}'
16b17b901c2c
72637ae4b155
1311ff40521a
2950365d3727
a065e3343191
fb1e4481b7ee
7a8f553d442d
adb679d80383
485abdefc669
```

`docker rmi` に渡せばOK

```
$ docker images | grep none | awk '{print $3}' | xargs docker rmi  # 冒頭のコマンドと同じ
Deleted: sha256:16b17b901c2c6f442b332e51fc992eaf9fe59b0fdc24b90c4adb384c9038b1f0
Deleted: sha256:707a7817183178340989e8b3ee54150be5d2893da4aa35f5c9be7faffa4c061a
Deleted: sha256:d8172c458aca769930f471a77d765e3e34e5b649b3fd5b8539fbf9f5efda6fb0
Deleted: sha256:8e4328145205c20cf53331cb85e2c4f354750f57550aa5dc5ce857ed9a64981a
Deleted: sha256:4c96b7934405ee88f12c2d8aa2c0ed9099dc4232d23fc93ad9aedd3d592d8a01
Deleted: sha256:9a0446b898565c758c4436cb447bce90d8ad5d0ce8a46263dc0adf3db747c802
Deleted: sha256:0f860452980e7f18ae0441001bc6d2cb61cf20b732c36a907dd9d8f52b35ac5f
Deleted: sha256:5c4a8f3efdaf62678bcb4614539e7353f76b82c40102846d985ead5ee44aed01
Deleted: sha256:d63d652b511adf53ebe2a2f4972ba7c5e5ac3b2749a95de88b217050f44a15a0
Deleted: sha256:812f8de3922484f7ced929898e3c7a358aa552d9d6ea5c7a0bdc5920deff8bd4
Deleted: sha256:98791ec771a8493002324d63e3e81b134770b0067c6d3927e4a55efe93655667
Deleted: sha256:763bdc8df9d91fbf4f86b1252b31358aefdf1f0b77d5c0800102e1cae6b40bd3
                                  :
                                  :
```