5

I'm newby in Devops culture and also eager to learn and use but I get stuck every time when i try something new and now i can't delete images. It says; it's being used by running container, stop it and then.....

See the screenshots:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

  • 1
    Please post formatted code rather than screenshots. Screenshots break search, copy and paste, and are less accessible. – BMitch Jul 24 '20 at 14:00

3 Answers3

13

Get running containers

docker ps

Get all running and stopped container

docker ps -a

Stop single container

docker stop <container_id>

Stop all containers

docker stop $(docker ps -aq)

Remove single container

docker rm <container_id>

Remove all containers

docker rm $(docker ps -aq)

Remove single image

docker rmi <image_id>

Remove all images

docker rmi $(docker images -q)

Remove everything from Docker host machine(use with caution because will delete everything like images, containers,networks etc)

docker system prune
Dashrath Mundkar
  • 7,956
  • 2
  • 28
  • 42
  • "docker rm" requires at least 1 argument. See 'docker rm --help'. Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...] Remove one or more containers – yunus emre görmüş Jul 24 '20 at 13:34
  • @yunusemregörmüş I have updated my answer will work now – Dashrath Mundkar Jul 24 '20 at 13:34
  • Error response from daemon: conflict: unable to delete e704287ce753 (cannot be forced) - image is being used by running container f01123318760 Error response from daemon: conflict: unable to delete 79da37e5a3aa (cannot be forced) - image is being used by running container 6d526abd025d Error response from daemon: conflict: unable to delete fc838b21afbb (cannot be forced) - image is being used by running container cf8ccd96d231 Error response from daemon: conflict: unable to delete 0ee1b8a3ebe0 (cannot be f-*** – yunus emre görmüş Jul 24 '20 at 13:38
  • @yunusemregörmüş try above commands it's working on my local. try again should definitely work – Dashrath Mundkar Jul 24 '20 at 13:43
  • i am struggling about one week. Nothing changed about simple commands – yunus emre görmüş Jul 24 '20 at 13:47
2

You can just force remove the image even when there is a container that is still using it, if you don't mind doing that.

docker image rm <image-name> --force

Best way to delete all stopped containers is

docker container prune 

As for the running containers, you should be able to list them with

docker container ls 

add (--all) to see all (running/stopped) containers

docker container ls --all
Matus Dubrava
  • 13,637
  • 2
  • 38
  • 54
1

Use docker ps -a to list all your running containers. You will find the ones still running. Stop them by using docker stop NAMEOFTHECONTAINER and remove them with docker rm NAMEOFTHECONTAINER.