OneBite.Dev - Coding blog in a bite size

remove all docker images

Simple docker step by step how to remove all docker images with explanation

In this article, you’ll learn how to quickly and effectively remove all Docker images from your system. Docker images are essential components of your Docker workflow, but occasionally, you might find it necessary to purge them to free up some space or start over with a fresh environment. Here’s a simple step-by-step guide to help you achieve this.

Prerequisites

Before you start, make sure Docker is installed and running on your system. You can verify this by typing docker version in your terminal. If Docker is fully functioning, it will output your currently installed version.

Step 1: Listing Docker images

The first thing you’ll want to do is list all Docker images stored on your system. This can be done by running the following command in your terminal:

docker images

This command will provide a list of all Docker images currently stored on your system, displaying their REPOSITORY, TAG, IMAGE ID, CREATED, and SIZE.

Step 2: Removing Docker images

Once you’ve reviewed your Docker images, it’s time to remove them. Docker offers a straightforward command to eliminate all Docker images. You can achieve this by typing the following command in your terminal:

docker rmi -f $(docker images -a -q)

This command does all the heavy lifting for you:

  • docker rmi is the base command for removing images.
  • -f is a flag that forces the removal of an image, even if it has multiple tags or is currently being used by stopped containers.
  • $(docker images -a -q) is a way to pass all image IDs to the docker rmi command. Here, -a lists all images (not just dangling ones), and -q stands for “quiet”, providing minimal output and listing only the numeric identifiers for the images.

Once executed, this command will remove all Docker images from your system.

Wrapping up

Congratulations, you have successfully removed all Docker images from your system. Remember that routinely trimming your Docker images can be an excellent practice to maintain a clutter-free environment and better utilize your storage space. However, you should always check what images are on your system before removing them to avoid any unintended losses.

docker