How to List and Remove Docker Image?

[ad_1]

Docker is a well known platform that permits you to set up run and send your packages as packing containers that bundle the OS and dependent libraries together with your utility in combination.

We’ll be masking managing Docker pictures, basically briefing in regards to the techniques to listing Docker pictures and get the specified knowledge and then construction upon that studying to take away a number of pictures in environment friendly manner.

So let’s get began.

Record Docker Pictures

To listing pulled Docker pictures, use:

[email protected]:~$ docker picture ls
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
redis         newest    aa4d65e670d6   9 days in the past      105MB
mysql         newest    c60d96bd2b77   10 days in the past     514MB
ubuntu        newest    c29284518f49   2 weeks in the past     72.8MB
nginx         newest    4cdc5dd7eaad   3 weeks in the past     133MB
hello-world   newest    d1165f221234   4 months in the past    13.3kB
redis         4.0       191c4017dcdd   15 months in the past   89.3MB
[email protected]:~$

As with different docker instructions, it helps pictures command with a couple of choices.

 $ docker pictures [OPTIONS] [REPOSITORY[:TAG]]

For those who run docker pictures with none choices, it’ll display you the top-level pictures like docker picture ls, their repository and tags and their measurement on disk.

[email protected]:~$ docker pictures
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
mysql         newest    c60d96bd2b77   10 days in the past     514MB
ubuntu        newest    c29284518f49   2 weeks in the past     72.8MB
nginx         newest    4cdc5dd7eaad   3 weeks in the past     133MB
hello-world   newest    d1165f221234   4 months in the past    13.3kB
redis         4.0       191c4017dcdd   15 months in the past   89.3MB
[email protected]:~$

Those pictures have intermediate layers that build up usability, accelerate the construct procedure, and reduces disk utilization which isn’t proven through the above command. The SIZE is the mixed house taken up through the picture and all its dad or mum pictures. For those who save the contents of the picture as a Tar record whilst you docker save a picture, it’ll equivalent this indexed measurement.

A picture will get indexed a couple of occasions if it has a couple of repository names or tags even though the one picture known through its IMAGE ID makes use of up the SIZE indexed handiest as soon as.

List most up-to-date pictures

[email protected]:~$ docker pictures
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
mysql         newest    c60d96bd2b77   10 days in the past     514MB
ubuntu        newest    c29284518f49   2 weeks in the past     72.8MB
nginx         newest    4cdc5dd7eaad   3 weeks in the past     133MB
hello-world   newest    d1165f221234   4 months in the past    13.3kB
redis         4.0       191c4017dcdd   15 months in the past   89.3MB
[email protected]:~$

List pictures through Repository and Tag

To listing all pictures that belong to a selected repository, specify the repository call like:

[email protected]:~$ docker pictures redis
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
redis        newest    aa4d65e670d6   9 days in the past      105MB
redis        4.0       191c4017dcdd   15 months in the past   89.3MB
[email protected]:~$

You’ll moreover specify the repository call with a tag for a extra filtered output:

[email protected]:~$ docker pictures redis:4.0
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
redis        4.0       191c4017dcdd   15 months in the past   89.3MB
[email protected]:~$

List full-length picture IDs

To listing all pictures with out truncating the IMAGE ID, use:

[email protected]:~$ docker pictures --no-trunc
REPOSITORY    TAG       IMAGE ID                                                                  CREATED         SIZE
redis         newest    sha256:aa4d65e670d6518e5da96ca9d1a76370a942970a8802e6d5cc6bcf058ab12ca7   9 days in the past      105MB
mysql         newest    sha256:c60d96bd2b771a8e3cae776e02e55ae914a6641139d963defeb3c93388f61707   10 days in the past     514MB
ubuntu        newest    sha256:c29284518f497b8c5f49933e74e43ca5221e69c8251e780427f7d12f716625ff   2 weeks in the past     72.8MB
nginx         newest    sha256:4cdc5dd7eaadff5080649e8d0014f2f8d36d4ddf2eff2fdf577dd13da85c5d2f   3 weeks in the past     133MB
hello-world   newest    sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726   4 months in the past    13.3kB
redis         4.0       sha256:191c4017dcdd3370f871a4c6e7e1d55c7d9abed2bebf3005fb3e7d12161262b8   15 months in the past   89.3MB
[email protected]:~$

List Symbol Digests

Docker pictures that use v2 or later structure have a content-addressable identifier referred to as a digest. To listing picture digest values, use --digest flag as:

[email protected]:~$ docker pictures --digests
REPOSITORY    TAG       DIGEST                                                                    IMAGE ID       CREATED         SIZE
redis         newest    sha256:cd0c68c5479f2db4b9e2c5fbfdb7a8acb77625322dd5b474578515422d3ddb59   aa4d65e670d6   9 days in the past      105MB
mysql         newest    sha256:8b928a5117cf5c2238c7a09cd28c2e801ac98f91c3f8203a8938ae51f14700fd   c60d96bd2b77   10 days in the past     514MB
ubuntu        newest    sha256:b3e2e47d016c08b3396b5ebe06ab0b711c34e7f37b98c9d37abe794b71cea0a2   c29284518f49   2 weeks in the past     72.8MB
nginx         newest    sha256:c5aab9d8e259d54af91e0548abf1fa8188a43079eb86b6ba8df9f482a5380720   4cdc5dd7eaad   3 weeks in the past     133MB
hello-world   newest    sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e   d1165f221234   4 months in the past    13.3kB
redis         4.0       sha256:2e03fdd159f4a08d2165ca1c92adde438ae4e3e6b0f74322ce013a78ee81c88d   191c4017dcdd   15 months in the past   89.3MB
[email protected]:~$

With a 2.0 registry, you’ll use those digests with push, pull, create, run and rmi instructions. This additionally works with FROM command in a Dockerfile.

Filtering the Output

docker command helps filtering with pictures through the use of --filter flag. The lately supported filters are:

  • dangling (boolean – true or false)
  • label (label=<key> or label=<key>=<price>)
  • ahead of (<image-name>[:<tag>]<picture identification> or <[email protected]>) – clear out pictures created ahead of given identification or references
  • since (<image-name>[:<tag>]<picture identification> or <[email protected]>) – clear out pictures created since given identification or references
  • reference (development of a picture reference) – clear out pictures whose reference fits the desired development

Additional, you’ll use a couple of filters through combining them like:

$ docker pictures --filter "<key1>=<value1>" --filter"<key2>=<value2>"

Instance:

[email protected]:~$ docker pictures --filter "ahead of=redis" --filter "since=hello-world"
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
mysql        newest    c60d96bd2b77   10 days in the past   514MB
ubuntu       newest    c29284518f49   2 weeks in the past   72.8MB
nginx        newest    4cdc5dd7eaad   3 weeks in the past   133MB
[email protected]:~$

Formatting the Output

docker pictures strengthen formatting output that can be wanted for nesting with different instructions, scripting, or differently. Those are the supported placeholders for the --format flag:

Placeholder Description
.ID Symbol ID
.Repository Symbol repository
.Tag Symbol tag
.Digest Symbol digest
.CreatedSince Elapsed time because the picture was once created
.CreatedAt The time when the picture was once created
.Dimension Symbol disk measurement

For instance, the under command prints the output with out headers and outputs the ID and Repository separated through colon ( : ) for all pictures:

[email protected]:~$ docker pictures --format ".ID: .Repository"
aa4d65e670d6: redis
c60d96bd2b77: mysql
c29284518f49: ubuntu
4cdc5dd7eaad: nginx
d1165f221234: hello-world
191c4017dcdd: redis
[email protected]:~$

Or to listing all pictures with their repository and tag in a desk structure, you’ll use:

[email protected]:~$ docker pictures --format "desk .IDt.Repositoryt.Tag"
IMAGE ID       REPOSITORY    TAG
aa4d65e670d6   redis         newest
c60d96bd2b77   mysql         newest
c29284518f49   ubuntu        newest
4cdc5dd7eaad   nginx         newest
d1165f221234   hello-world   newest
191c4017dcdd   redis         4.0
[email protected]:~$

Taking out Docker Pictures

To take away a number of Docker pictures from the device, we use:

$ docker picture rm [OPTIONS] IMAGE [IMAGE...]

To take away a unmarried picture, merely specify the picture call:

[email protected]:~$ docker picture rm redis
Untagged: redis:newest
Untagged: [email protected]:cd0c68c5479f2db4b9e2c5fbfdb7a8acb77625322dd5b474578515422d3ddb59
Deleted: sha256:aa4d65e670d6518e5da96ca9d1a76370a942970a8802e6d5cc6bcf058ab12ca7
Deleted: sha256:3bd00d38f5ca70200050477c527cc60cfdf82911d6fe03932e2bcae31a95cfa2
Deleted: sha256:22722fde392d188cfbe5bbd0c2451cc71cf5b000afc0e5114c1066bb5e113ec9
Deleted: sha256:38212b55ef525e86cd726cd83c1a82a6009c68d24771d6e93d439fdc88e66f0e
Deleted: sha256:188c498579cef37b65a93d6448c6b129fa07d5740fc213a18843ff22d80cd10d
Deleted: sha256:2117165cd53c98f13ec7af36c9d8acd239fc541c847efaccb49885decf615d68
[email protected]:~$

Or to take away a couple of pictures, specify a couple of picture names separated through house:

[email protected]:~$ docker picture rm redis mariadb
Untagged: redis:newest
Untagged: [email protected]:cd0c68c5479f2db4b9e2c5fbfdb7a8acb77625322dd5b474578515422d3ddb59
Deleted: sha256:aa4d65e670d6518e5da96ca9d1a76370a942970a8802e6d5cc6bcf058ab12ca7
Deleted: sha256:3bd00d38f5ca70200050477c527cc60cfdf82911d6fe03932e2bcae31a95cfa2
Deleted: sha256:22722fde392d188cfbe5bbd0c2451cc71cf5b000afc0e5114c1066bb5e113ec9
Deleted: sha256:38212b55ef525e86cd726cd83c1a82a6009c68d24771d6e93d439fdc88e66f0e
Deleted: sha256:188c498579cef37b65a93d6448c6b129fa07d5740fc213a18843ff22d80cd10d
Deleted: sha256:2117165cd53c98f13ec7af36c9d8acd239fc541c847efaccb49885decf615d68
Untagged: mariadb:newest
Untagged: [email protected]:3b6f9fa1d406e168998d62501b2ee4f27d53138bebfcdac03540758996c5ff1d
Deleted: sha256:fd17f57768027456cc17987058474fb21d3c51e9dd764e4497c1dfe92ff058db
Deleted: sha256:a638f04e531b032c81a84bda59a36d1df3c4cec62560c403bc2edb642bce79ba
Deleted: sha256:af7a7e7bf72e7ad0c5227995f219d9094fafbe0ac973dbe7eb4ab190a5a58ba5
Deleted: sha256:a0cfd81b291e8da6bca0731c9db70fe1b61d176906b1cf05ade1cd61572ffaaa
Deleted: sha256:38b00cb5dab64398092fab2b18563af1ef4a9445dec8a531ac725059dc218f41
Deleted: sha256:6e60d29d2d76125f989f503a78729984f7ba3e26bfbf7038d5ab644b8755b7c2
Deleted: sha256:1dafdd60e471b4c1f5244cfe1d20d79f934f504ef42180b637886be2b0b74370
Deleted: sha256:2fffe8e736cdb99359084e297f4bb54a4cac879366bd3e4333d3dbe966f8e9a6
Deleted: sha256:f728037697805db453111266541c202c74971484ef359ea29b9c60064ed9e47e
Deleted: sha256:28155a13db3520201db576bf6d56b68fc08ef27b1c4c49dbfeadef523d35c5f0
Deleted: sha256:7555a8182c42c7737a384cfe03a3c7329f646a3bf389c4bcd75379fc85e6c144
[email protected]:~$

Power Removing

There could also be packing containers operating which are the use of the photographs which you’re making an attempt to delete. In such instances, Docker will factor you a caution whilst you check out to delete a referenced picture.

[email protected]:~$ docker picture rm nginx
Error reaction from daemon: battle: not able to take away repository reference "nginx" (will have to power) - container ce908eadf829 is the use of its referenced picture 4cdc5dd7eaad
[email protected]:~$

You’ll forestall the related container first and then retry or else use -f flag which forces the picture elimination (watch out).

[email protected]:~$ docker picture rm nginx -f
Untagged: nginx:newest
Untagged: [email protected]:c5aab9d8e259d54af91e0548abf1fa8188a43079eb86b6ba8df9f482a5380720
Deleted: sha256:4cdc5dd7eaadff5080649e8d0014f2f8d36d4ddf2eff2fdf577dd13da85c5d2f
[email protected]:~$

Prune Pictures

There are particular scenarios the place unused pictures are eating disk house otherwise you simply want a cleanup of outdated dangling pictures. You’ll blank such unused pictures through the use of:

$ docker picture prune

Instance:

[email protected]:~$ docker picture prune
WARNING! This will likely take away all dangling pictures.
Are you positive you need to proceed? [y/N] y
Overall reclaimed house: 0B
[email protected]:~$

If you want to blank up all pictures which aren’t utilized by any packing containers as neatly, use -a flag:

[email protected]:~$ docker picture prune -a
WARNING! This will likely take away all pictures with out a minimum of one container related to them.
Are you positive you need to proceed? [y/N] y
Deleted Pictures:
untagged: mariadb:newest
untagged: [email protected]:3b6f9fa1d406e168998d62501b2ee4f27d53138bebfcdac03540758996c5ff1d
deleted: sha256:fd17f57768027456cc17987058474fb21d3c51e9dd764e4497c1dfe92ff058db
deleted: sha256:a638f04e531b032c81a84bda59a36d1df3c4cec62560c403bc2edb642bce79ba
deleted: sha256:af7a7e7bf72e7ad0c5227995f219d9094fafbe0ac973dbe7eb4ab190a5a58ba5
deleted: sha256:a0cfd81b291e8da6bca0731c9db70fe1b61d176906b1cf05ade1cd61572ffaaa
deleted: sha256:38b00cb5dab64398092fab2b18563af1ef4a9445dec8a531ac725059dc218f41
deleted: sha256:6e60d29d2d76125f989f503a78729984f7ba3e26bfbf7038d5ab644b8755b7c2
deleted: sha256:1dafdd60e471b4c1f5244cfe1d20d79f934f504ef42180b637886be2b0b74370
deleted: sha256:2fffe8e736cdb99359084e297f4bb54a4cac879366bd3e4333d3dbe966f8e9a6
deleted: sha256:f728037697805db453111266541c202c74971484ef359ea29b9c60064ed9e47e
deleted: sha256:28155a13db3520201db576bf6d56b68fc08ef27b1c4c49dbfeadef523d35c5f0
deleted: sha256:7555a8182c42c7737a384cfe03a3c7329f646a3bf389c4bcd75379fc85e6c144
untagged: redis:newest
untagged: [email protected]:cd0c68c5479f2db4b9e2c5fbfdb7a8acb77625322dd5b474578515422d3ddb59
deleted: sha256:aa4d65e670d6518e5da96ca9d1a76370a942970a8802e6d5cc6bcf058ab12ca7
deleted: sha256:3bd00d38f5ca70200050477c527cc60cfdf82911d6fe03932e2bcae31a95cfa2
deleted: sha256:22722fde392d188cfbe5bbd0c2451cc71cf5b000afc0e5114c1066bb5e113ec9
deleted: sha256:38212b55ef525e86cd726cd83c1a82a6009c68d24771d6e93d439fdc88e66f0e
deleted: sha256:188c498579cef37b65a93d6448c6b129fa07d5740fc213a18843ff22d80cd10d
deleted: sha256:2117165cd53c98f13ec7af36c9d8acd239fc541c847efaccb49885decf615d68

Overall reclaimed house: 445.2MB
[email protected]:~$

You’ll additionally use --force or -f flag to continue to blank with out affirmation or use --filter flag to supply clear out values (e.g. ‘till=<timestamp>’) to the prune command.

Instance:

$ docker picture prune -a --force --filter "till=2021-01-04T00:00:00"

Or

$ docker picture prune --filter="label=deprecated"

The use of rmi Command

You’ll additionally use rmi command with docker to take away pictures.

It eliminates (and un-tags) a number of pictures from the Docker node. If a picture has a couple of tags, the use of this command with the tag as a parameter handiest eliminates the tag. If the tag is the one one for the picture, each the picture and the tag are got rid of.

This command does now not take away pictures from a registry. Additionally, you can’t take away a picture of a operating container except you utilize the -f possibility as with docker picture rm command.

Instance:

[email protected]:~$ docker rmi alpine
Untagged: alpine:newest
Untagged: [email protected]:adab3844f497ab9171f070d4cae4114b5aec565ac772e2f2579405b78be67c96
Deleted: sha256:d4ff818577bc193b309b355b02ebc9220427090057b54a59e73b79bdfe139b83
Deleted: sha256:72e830a4dff5f0d5225cdc0a320e85ab1ce06ea5673acfe8d83a7645cbd0e9cf
[email protected]:~$

You’ll additionally use --no-prune to specify now not to delete untagged folks.

Forestall Container and Remove Pictures

On many events, it’s possible you’ll want to forestall all packing containers and take away all related pictures. You’ll do this merely with:

$ docker rm -vf $(docker playstation -a -q)

The above command will forestall and take away all operating packing containers forcefully. Then we will be able to continue to take away the connected pictures through the use of:

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

Abstract

Docker is a flexible software this is an crucial a part of lately’s DevOps engineer’s arsenal and is a part of different humming applied sciences like Kubernetes. Docker picture control is among the crucial portions of managing and troubleshooting a Docker deployment.

You must now have a fundamental concept of the functions that docker CLI command gives with its instructions like picture, pictures and rmi. Their flags be offering additional customization and be offering complicated filtering and customization choices that may lend a hand in automation and complicated utilization.

Use docker [COMMAND] lend a hand for additional information about to be had choices and comparable lend a hand subjects.

[ad_2]

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button