Nothing Special   »   [go: up one dir, main page]

Skip to content

Instantly share code, notes, and snippets.

@andyrbell
Last active June 3, 2024 16:58
Show Gist options
  • Save andyrbell/f30ae74c0eff82ae52238f4a7df9a313 to your computer and use it in GitHub Desktop.
Save andyrbell/f30ae74c0eff82ae52238f4a7df9a313 to your computer and use it in GitHub Desktop.
Sort docker images by size desc
#!/bin/sh
docker images --format '{{.Size}}\t{{.Repository}}\t{{.Tag}}\t{{.ID}}' | sed 's/ //' | sort -h -r | column -t
@Aracki
Copy link
Aracki commented Jun 15, 2018

nice alternative:

alias dis='docker images --format '{{.Size}}\t{{.Repository}}' | sort -r'

@jthomerson
Copy link

@Aracki yours needs to be sort -hr (added h) to sort things correctly when you have different scales of sizes reported (e.g. some are 4MB, 95.3MB, and others are 1.02GB.

@cuongtransc
Copy link

More pretty:

docker images --format '{{.Size}}\t{{.Repository}}:{{.Tag}}\t{{.ID}}' | sort -h | column -t

@andyrbell
Copy link
Author

@cuongtransc thanks. have updated with the column -t

@quantonganh
Copy link
docker images | sort -k7 -h

@MrBuBBLs
Copy link

Showing & keeping the leading column title where they are:

docker images | awk 'NR<2{print $0;next}{print $0| "sort -k7 -hr"}'

Add | head to get only the biggest ones

@emsi
Copy link
emsi commented Aug 20, 2019
docker images | sort -k7 -h

@quantonganh Like a pro! :) Kudos.

@ciarancourtney
Copy link

To be clear, its -k7, not -k5, because there are generally two spaces in the preceding CREATED column

@ddefrancesco
Copy link

Schermata 2019-09-21 alle 13 50 06

Nice, very clear, could used by default...unuseful to me though because it's not a real sort by size that I looked for, I'll keep searching, thx anyway...

@ksilz
Copy link
ksilz commented Nov 27, 2019

docker images | sort -k7 -h

@quantonganh Great one! I just added an -r to show the biggest image first:

docker images | sort -k7 -h -r

@ksilz
Copy link
ksilz commented Nov 27, 2019

docker images | sort -k7 -h

@quantonganh I referenced your command in another post.

@simne7
Copy link
simne7 commented Feb 26, 2020

I had to replace the decimal separator in dockers {{.Size}} which seems to be always a dot, with the one of my locale to make sort -h work properly.

docker images --format '{{.Size}}\t{{.Repository}}:{{.Tag}}\t{{.ID}}' | sed 's/\./,/' | sort -hr | column -t

Note: the sed command blindly replaces the first "." per line.

@emsi
Copy link
emsi commented Feb 27, 2020

I had to replace the decimal separator in dockers {{.Size}} which seems to be always a dot, with the one of my locale to make sort -h work properly.

Setting locale collate would do the trick as well. Something like this should work too:
docker images | LC_COLLATE=C.UTF-8 sort -k7 -hr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment