Skip to content

Docker

Usage

List images by descending size

$ docker images --format '{{.Size}}\t{{.Repository}}\t{{.Tag}}\t{{.ID}}' | sed 's/ //' | sort -h -r | column -t

Cleaning up

Remove all dangling data

Delete all dangling data (i.e. in order: stopped containers, volumes without containers and images with no containers). Even unused data, with -a/--all option.

$ docker system prune

Remove dangling containers

$ docker containers prune

Remove dangling images

$ docker image prune

Remove dangling volumes

$ docker volume prune

Remove dangling networks

$ docker network prune

Remove tagged images older than a month

$ docker images --no-trunc --format '{{.ID}} {{.CreatedSince}}' \
    | grep ' months' | awk '{ print $1 }' \
    | xargs --no-run-if-empty docker rmi