docker-logo

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

delete-image-1

……なので、次はコマンドプロンプトから削除を試みた。

Docker image の削除

イメージIDを確認

まずはcmdを開き、

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
Docker

harpooncorpのイメージIDはf98662356607とわかったので、rmiで削除。

# image ID で削除
rmi f98662356607
Docker

が、下記のエラーメッセージが出てきて削除できず。

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
Docker

下記エラーメッセージ。

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
Docker

これでイメージが削除できるかなと思って再度 rmi をトライしたら、

docker rmi f98662356607
Docker

コンテナの停止だけではなくて削除する必要があるとのこと。

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

イメージの削除

その後、docker rmi でイメージを削除すると、

docker rmi f98662356607
Docker

イメージが削除できた。

delete-image-2

Reference