To see all the images I have installed, I run docker images
. I'd like to sort all my images by "SIZE". How can I do this? More generally, how does one sort the returned images by any parameter, such as "CREATED"
To view the approximate size of a running container, you can use the command docker container ls -s . Running docker image ls shows the sizes of your images. To see the size of the intermediate images that make up your image use docker image history my_image:my_tag .
The easiest way to list Docker images is to use the “docker images” with no arguments. When using this command, you will be presented with the complete list of Docker images on your system. Alternatively, you can use the “docker image” command with the “ls” argument.
docker images supports --format flag to customize output -> https://docs.docker.com/engine/reference/commandline/images/#format-the-output
Adding custom formatting and using sort does the trick:
docker images --format "{{.ID}}\t{{.Size}}\t{{.Repository}}" | sort -k 2 -h
None of the answers correctly show how to sort the actual docker images
command.
Here is a bona fide solution:
docker images | sort -k7 -h
Logical solution should be
docker images | sort -k5 -h
but this doesn't work, because docker emits spaces instead of tabs.
Created issue for that(https://github.com/docker/cli/issues/2406).
If you have time and know go, please contribute the fix :)
Till fixed, you can use some wrapper script like https://github.com/pixelastic/oroshi/blob/master/scripts/bin/docker-image-list
If using PowerShell, you can sort by arbitrary fields such as repo/image name as follows:
docker images --format="{{json .}}" |
ConvertFrom-Json |
Sort-Object Repository |
Select-Object Repository,Tag,ID,CreatedSince,Size |
Format-Table
though sadly it doesn't work well on human-readable fields such as Size
so it unfortunately doesn't answer the more specific first part of your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With