Task no. 17 in "DOCKER COMMANDS, LABS: BASIC DOCKER COMMANDS"

Hello,

This issue is for the docker course. “Docker Training Course for the Absolute Beginner | KodeKloud

Task no. 17 in “DOCKER COMMANDS, LABS: BASIC DOCKER COMMANDS”
Cleanup: Delete all images on the host

I followed the steps as mentioned, I removed all the images using “docker rmi $(docker images -aq)”

But, seems some container is using one image.
$ docker rmi $(docker images -aq)
Error response from daemon: conflict: unable to delete 8a2fb25a19f5 (must be forced) - image is being used by stopped container ec47b38520f3

what is the recommended steps to manage this scenario ? Could you pleas provide the docker commands for this?

Hi @girishs22,

You need to remove the stopped container first. Run the following command:

docker rm $(docker ps -aq)

and then, remove the images.

Regards,

Hello Tej,

I am still facing some issues. Please see below.

rm $(docker ps -aq)
rm: cannot remove ‘b3dfbe1e2bb8’: No such file or directory
rm: cannot remove ‘95a3d224202f’: No such file or directory
rm: cannot remove ‘6f674c3f1b58’: No such file or directory
rm: cannot remove ‘92baf4abe133’: No such file or directory
rm: cannot remove ‘c4eece401179’: No such file or directory
rm: cannot remove ‘c6b51fc2e2bb’: No such file or directory

docker rm $(docker ps -aq)
rm: cannot remove ‘b3dfbe1e2bb8’: No such file or directory
rm: cannot remove ‘95a3d224202f’: No such file or directory
rm: cannot remove ‘6f674c3f1b58’: No such file or directory
rm: cannot remove ‘92baf4abe133’: No such file or directory
rm: cannot remove ‘c4eece401179’: No such file or directory
rm: cannot remove ‘c6b51fc2e2bb’: No such file or directory

docker rmi $(docker images -aq)
Error response from daemon: conflict: unable to delete 8e75cbc5b25c (cannot be forced) - image is being used by running container c4eece401179
Error response from daemon: conflict: unable to delete 9ed4aefc74f6 (cannot be forced) - image is being used by running container 6f674c3f1b58
Error response from daemon: conflict: unable to delete 08d22c0ceb15 (cannot be forced) - image is being used by running container c6b51fc2e2bb
Error response from daemon: conflict: unable to delete 8a2fb25a19f5 (cannot be forced) - image is being used by running container b3dfbe1e2bb8

unable to delete 8a2fb25a19f5 (cannot be forced) - image is being used by running container b3dfbe1e2bb8

Hi @girishs22,

Please read the error output - “Image is being used by the running container”
First, you have to stop all the running containers before deleting them.

docker stop $(docker ps -aq)

then try the above suggested commands.

Regards,

@Tej-Singh-Rana Thanks, I have noted the command to stop all the containers.