Docker Maintenance - Reclaim Disk Space

Published: 2024-07-03 | Updated: 2024-07-03

Over time Docker will consume more and more disk space on your local machine. Every time you remove a volume, a network, an image, or a container there will be some remnant of that entity just taking up space. Use these quick commands to clean it up

Volumes

# removes anonymous local volumes not used by at 
# least one container
docker volume prune
WARNING! This will remove all local volumes not used by at least one container.
Are you sure you want to continue? [y/N]
# remove all local volumes not used by at least 
# one container
docker volume prune -a
WARNING! This will remove all local volumes not used by at least one container.
Are you sure you want to continue? [y/N]

Images

# removes anonymous local images not used by at least
# one container
docker image prune
WARNING! This will remove all images without at least one container associated to them.
Are you sure you want to continue? [y/N]
# removes all local images not used by at least
# one container
docker image prune -a
WARNING! This will remove all images without at least one container associated to them.
Are you sure you want to continue? [y/N]

Networks

# removes anonymous local networks not used by at least
# one container
docker network prune
WARNING! This will remove all custom networks not used by at least one container.
Are you sure you want to continue? [y/N]

Major House Cleaning

Everything Everywhere All at Once

If you’re really serious about removing every last bit of Docker cruft, this will do it. Fair warning though, anything not currently in use will be swept up and tossed.

docker system prune -a
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all images without at least one container associated to them
  - all build cache

Are you sure you want to continue? [y/N]