How to sort my Docker images by size with `docker images` command?

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

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

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