Virtualization

如何刪除頑固的 docker 鏡像?

  • August 27, 2014

我試圖按如下方式刪除 Docker 映像,但不知道如何執行此操作。

泊塢窗圖像列表

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED              VIRTUAL SIZE
<none>              <none>              04251cf7a8b9        About a minute ago   356.1 MB
pg-image            latest              1060b3e656b6        5 minutes ago        323.9 MB
redis-image         latest              8df469463da3        14 minutes ago       137.7 MB
ubuntu              12.04               822a01ae9a15        2 weeks ago          108.1 MB

我要刪除的 Docker 映像:

$ docker rmi 042
Error response from daemon: Conflict, cannot delete 04251cf7a8b9 because 
the container 4ac3a09ab4d3 is using it, use -f to force
2014/08/27 15:16:15 Error: failed to remove one or more images

當我嘗試使用它刪除它時,-f它沒有成功。如何正確刪除此圖像,為什麼不能使用 刪除它docker rmi -f 042

這裡的問題是有一個容器 4ac3a09ab4d3,它仍在使用這個圖像。

$ docker ps -a
CONTAINER ID        IMAGE                COMMAND                CREATED             STATUS                       PORTS               NAMES
4ac3a09ab4d3        04251cf7a8b9         /bin/sh -c ./git_che   2 minutes ago       Exited (128) 2 minutes ago                       trusting_hawking
02c14db1bc65        pg-image:latest      /usr/lib/postgresql/   5 minutes ago       Up 5 minutes                                     postgres
6a022281382f        redis-image:latest   /usr/bin/redis-serve   8 minutes ago       Up 8 minutes                 6379/tcp            redis-db

您需要先刪除此容器,然後才能刪除此圖像。

# removes container 4ac3a09ab4d3
$ docker rm 4ac

# removes image 04251cf7a8b9
$ docker rmi 042
Deleted: 04251cf7a8b9efd81b8de6fbc0099f12a7933307bd4ecdadbaa9f1672b4a5f8f
Deleted: 7f76b7a22ef2c66a148714980716e7d01d97455b303cbeb7cc371ccba8bb5153
Deleted: bb7221a7b4a01573b0e3a175f3242f5e0ef58371c89a59dec7831146d6102bf8
Deleted: 493a63262d20f2a3ffc050c85d30528ab8a93c9dd2718fdb27dbbaac1a551c06
...

並且容器 (4ac3a09ab4d3) 和圖像 (04251cf7a8b9) 都已從您的系統中刪除。

引用自:https://unix.stackexchange.com/questions/152455