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.

Advertisement

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
Share.
Leave A Reply

Exit mobile version