Skip to content

How to Remove All Unused Objects in Docker

The docker system prune command removes all unused objects in Docker. This will remove any stopped container, unused images, and all the unused networks.

Covers
Docker
Versions & support
About Docker →

The docker system prune command is used to remove all unused objects on Docker. This command will remove any stopped container, unused images, and all the unused networks.

You may like:

Docker Remove Unused Objects

Log in to the Docker host and open the command prompt. Then execute the following command to remove stopped container, dangling images, and all the unused networks.

docker system prune

WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all dangling images
        - all build cache
Are you sure you want to continue? [y/N]

The default command will prompt for the confirmation. Press ‘y’ to continue. To ignore the confirmation prompt use the -f or --force flag like below

docker system prune --force

To remove all unused images (not only daggling one) use --all or -a flag with prune command. The docker images consist of multiple layers. The Dangling images are layers that have no relationship to any tagged images.

docker system prune --all

By default, the docker system prune command doesn’t remove unused volumes to prevent accidental data loss. But you can use the --volumes flag to prune volumes as well:

docker system prune --volumes

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top