Docker

Working with Images – Listing and Removing Docker Images

Working with Images - Listing and Removing Docker Images

Listing and Removing Docker Images for better understanding

Docker image is an important part of the whole docker’s architecture, as it is the main source from which our containers are going to be created with the help of docker, therefore they are necessary.

Listing Docker Images

Here, with the help of few commands, we are able to see available docker images in our system (locally).

Via running the command below, we can see that we have two available images in our local library or on our local system:

  1. Ubuntu
  2. Alpine

List docker image with “full details”

list docker images

sudo docker image ls

List docker image with only “Image ID’s”

We can also only see the “Images ID’s” of images and avoid the other details by using the following command.

list docker image with only image id

sudo docker image ls -q

Removing Docker Images

Again, with the help of following commands, it becomes easy and handy to remove docker images.

Remove docker image using “Image name”

Simply running the command below, we can see that we are able to delete our locally present “alpine” image.

remove docker image with name

sudo docker image rm alpine

Now, when we try to see the available images on our system, from the image below it is seen that only the “Ubuntu” image is left on our system.

list docker image

Remove docker image using “Image ID”

We can also remove by only providing the “Image ID’s” of available images.

Remove docker image using Image ID

After removing the “Ubuntu” image using its “Image ID“, we can see from below that there are “0 Images” available in our system, at the current moment.

list docker images

Remove all docker images at once with one command

Currently, we can see that we have following two images available in our system:

  1. nginx
  2. alpine
list docker image

Now, by running the combination or following commands, we can delete or remove all the available images in our system, at once.

Remove all docker images at once with one command

sudo docker image rm $(sudo docker image ls -q)

After executing the above command, we can confirm that we are able to remove all the images present in our system at once, as shown below.

Conclusion “Listing and Removing Docker Images”

We have learned about checking the docker images and then if needed how to remove them.

Comment here