
Docker のイメージ harpooncorp/harpoon-ext を削除しようとしたら、"Delete the container that's using it and try again" という警告が出てきて、削除できなかった。

……なので、次はコマンドプロンプトから削除を試みた。
Docker image の削除
イメージIDを確認
まずはcmdを開き、

docker images
でイメージIDを確認。
# image ID を確認
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
harpooncorp/harpoon-ext 0.0.4 f98662356607 3 months ago 12.5MB
harpooncorpのイメージIDはf98662356607とわかったので、rmi
で削除。
# image ID で削除
rmi f98662356607
が、下記のエラーメッセージが出てきて削除できず。
Error response from daemon: conflict: unable to delete f98662356607 (cannot be forced) - image is being used by running
container edd7a8e80afa
まずは docker rm
でコンテナを削除しようとしたら、
docker rm edd7a8e80afa
下記エラーメッセージ。
Error response from daemon: You cannot remove a running container
edd7a8e80afa21232da904bed8171d94ebcc418d075af037e4005e74afcc71bd. Stop the container before attempting removal or force
remove
コンテナの停止
「まずはコンテナを停止しなさい。」と言われたので、docker container stop
で停止。
docker container stop edd7a8e80afa
これでイメージが削除できるかなと思って再度 rmi
をトライしたら、
docker rmi f98662356607
コンテナの停止だけではなくて削除する必要があるとのこと。
Error response from daemon: conflict: unable to delete f98662356607 (must be forced) - image is being used by stopped
container edd7a8e80afa
コンテナの削除
なので、docker rm
でコンテナを削除。
docker rm edd7a8e80afa
イメージの削除
その後、docker rmi
でイメージを削除すると、
docker rmi f98662356607
イメージが削除できた。

Reference
It’s useful to clean all or specific Docker images and containers. Below are some handy commands to clean up,