How to Remove Images and Containers in Docker

By | July 6, 2022

Sometimes we might need to remove docker containers and images. This blog will guide you for the steps needed to do so.

Docker Architecture


Remove All Image [At Once]

To remove all images: docker rmi $(docker images -q)

Remove Multiple images

To remove multiple images at one command, you can follow this: docker rmi <your-image-id> <your-image-id>

Remove Container by name:

Removes containers by their name or ID: docker rm 

First you need to stop running container, before deleting them.

Stop all running containers: docker stop $(docker ps -a -q)

Delete all stopped containers: docker rm $(docker ps -a -q)

Remove multiple containers

You can stop and delete multiple containers by passing the commands a list of the containers you want to remove.

docker ps -a -q

  • docker ps list containers
  • -a the option to list all containers, even stopped ones. Without this, it defaults to only listing running containers
  • -q the quiet option to provide only container numeric IDs, rather than a whole table of information about containers

Caution: This blog is considering that you have minimum idea about docker