Tutorial 2 : Listing and Deleting Docker Containers and Images

Gaurav Patil
3 min readSep 4, 2022
Photo by Rubaitul Azad on Unsplash

Missed previous tutorial ? : click here.

We will cover following topics in this tutorial:

Listing Docker images

Listing Docker containers

Deleting Docker images

Deleting Docker containers

Listing Docker images :

In previous tutorial, we pulled and ran Docker image “hello-world”.

Let’s try to check the list of all the Docker images in your machine by running following command in a command prompt :

docker images

Output :

Above command will give the list all the Docker images along with it’s ID.

Listing Docker containers :

Run following command in a command prompt to check the list of all the Docker containers :

docker ps -a

Output :

You can see the all containers (running and exited) with names and Ids.

You can also run “docker ps” command to check all the running containers.

Deleting Docker images :

docker rmi -f <1Image_ID> <2Image_ID> <3Image_ID> ...

In above command, ‘rmi’ is for removing image and ‘-f’ indicates forceful removal.

Deleting Docker image needs image Id. So we run following command in a command prompt :

docker images

Above command will enlist all the images with image ID. Copy the ID of the image to be deleted and run following command :

docker rmi -f feb5d9fea6a5

For deleting multiple images, you can write multiple image IDs separated by space.

Output :

Now let’s check if the image is deleted or not :

docker images

Output :

Above output clearly shows that respective image is deleted successfully.

Deleting Docker containers :

docker rm -f <1container_ID> <2container_ID> <3container_ID> ...

In above command, ‘rm’ is for removing the container and ‘-f’ indicates forceful removal.

Deleting Docker container needs it’s ID. So we run following command in a command prompt :

docker ps -a 

Above command will enlist all the containers with ID. Copy the ID of the container to be deleted and run following command :

docker rm -f 270503e33fc2

For deleting multiple containers, you can write multiple container IDs separated by space.

Output :

Now let’s check if the container is deleted or not :

docker ps -a

Output :

Above output clearly shows that respective container is deleted successfully.

Now that you know how to check the list of all the Docker images and containers and how to delete them, how can you start(up the container) and stop the containers ?

Take a deep breath and move to the next tutorial .

--

--

Gaurav Patil

Machine Learning Engineer drawing insights from mathematics.