How to Delete Docker Images on your System

Last updated on November 7, 2021 A Goodman Loading... Post a comment

Overview

If there are some pulled images that you are no longer need then you can remove them from your system to free up your storage with the following command:

docker image rm

rm stands for remove.

One important thing we need to point out is that an image can only be deleted if it is not used by any containers, whether they are running or stopped. If you try to delete this image, you will see an error message like this:

Error response from daemon: conflict: unable to remove repository reference "node:latest" (must force) - container bf5747a7bccc is using its referenced image 7220633f01cd

In this case, what you have to do is to wipe out the associated containers first:

docker container rm <Container ID>

Deleting a single image

You can delete a single image by using its ID:

docker image rm <image ID>

Or name:

docker image rm <image name>

To see names and IDs of images on your Docker host, use this command:

docker image ls

Example:

docker image rm node:latest

Output:

Untagged: node:latest
Untagged: [email protected]:a562ce5da0b5e43107b4acbc5d8845129370f11bcb81c795601dc3d6004d6158
Deleted: sha256:7220633f01cdab3c20b7ded7f04e43e5b1ca95a5c5376a27e8fe41793d2dba6f
Deleted: sha256:477b901f817630d2e4c63167ec3d02df3260335cfa16b6ebf52cbee47e23ea23
Deleted: sha256:7304742164eed9f4f3c37bcd2812775660c7dfdbcc488d6c7747a1bdb9b1b0d6
Deleted: sha256:5d718b2a62801d9855070f344fceaf1fa83366f7e6f66b4e3cc59a74d581bc3f
Deleted: sha256:51e00c2f20febb20b8e1748361d239869b324f8da84328bed68a27aef8edf436
Deleted: sha256:e67b6800e9e8882c7060611038966ea29afe619bce27d0ea01528979a0f5c0fd
Deleted: sha256:995950c940fdede4906e13ddb5a13691b727b942a9b67afc23cc0172d80897a8
Deleted: sha256:b7a4a299f0c4a0e9d6f4156cd61b3a00c0595d9ee3db2dd7888f3a855b541fd6
Deleted: sha256:a9e0e6b8fdcd469c8785099c4559093696ad2c7da957d355557a17ed1bb8d23f
Deleted: sha256:62a747bf1719d2d37fff5670ed40de6900a95743172de1b4434cb019b56f30b4

Deleting multiple images

You can delete multiple images at once like this:

docker image rm ID-1 ID-2 ID-3 

Or:

docker image rm name1 name2 name3

Example:

docker image rm cabb9f684f8b 317a302c7480

Output:

Untagged: busybox:latest
Untagged: [email protected]:15e927f78df2cc772b70713543d6b651e3cd8370abf86b2ea4644a9fba21107f
Deleted: sha256:cabb9f684f8ba3edb303d578bfd7d709d853539ea1b420a3f6c81a08e85bb3d7
Deleted: sha256:a9ca537752fdf30df0dfe9fcd4ba936db4acbe0e991c9e4704c284bffed54eb5
Untagged: postgres:latest
Untagged: [email protected]:db927beee892dd02fbe963559f29a7867708747934812a80f83bff406a0d54fd
Deleted: sha256:317a302c7480940058992f178529b793ab83da4f548d5c3a179ce024ca034e92
Deleted: sha256:4201d48df683a14f3a8d0c7b8c7f0142828205f1cddce9427143de06a07f814c
Deleted: sha256:20a7d5a0e95534ce5b9092ca2ac1449d44919ca4a559ddbdd5e415ceb0c3ae3e
Deleted: sha256:d9c07cd5afaff166f5e5e1c8998f30eab6b7717d981d5d7de7c2ceb9674448f3
Deleted: sha256:fba6d55365bb7a6438924308ed8e1ba92dca6ad61324e4c9cfc85ffc722327a7
Deleted: sha256:ae8655dec288e67881d3a279fbc0a7d4b05d8758df0d7cf0d393361d978d8e73
Deleted: sha256:96da3fdc924507e29d7e21d1d4af966603fd32098b663d9257bdde5ac3dab26b
Deleted: sha256:dad7b34246eda639cdc792bbdc8ed0f4d304d39529bbc74601c5825bbcedf064
Deleted: sha256:9c42f74bc21dd7afbdf26a475c7775335c70c90c2a534408c5e0324e44af4a55
Deleted: sha256:11e5f4ba21a967372a09f304ac4086896bf19dce6a4ac11f7e320843ce27d4c2
Deleted: sha256:a20f46283106248688a912a681752981c5bf78db894f78d9e5d9b13442d1f8ba
Deleted: sha256:11a845317f4ce77d3823883d2f1a23b6f5b840fb96d1a35e169825730556111d
Deleted: sha256:aeb26a1aea82880ebbc393477e406cbd68278d09777d76d16b14d7c774199e86
Deleted: sha256:e8b689711f21f9301c40bf2131ce1a1905c3aa09def1de5ec43cf0adf652576e

Removing all unused images without IDs and names

In case you want to quickly clean up your machine by removing all unused Docker images at once, you can use the -q tag:

docker image rm -q

No IDs or names need to be passed.

Conclusion

We’ve learned how to make pulled images go away as we no longer need them. If you’d like to explore more new and exciting things about Docker, take a look at the following articles:

You can also check out our Docker topic page for the latest tutorials, examples, tips, and tricks.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Related Articles