Skip to content

Instantly share code, notes, and snippets.

@KeyurRamoliya
Created September 23, 2023 08:06
Show Gist options
  • Save KeyurRamoliya/4e4f543f10dc71dd60b1bb531719ff89 to your computer and use it in GitHub Desktop.
Save KeyurRamoliya/4e4f543f10dc71dd60b1bb531719ff89 to your computer and use it in GitHub Desktop.
Prune Unused Resources in Docker

Prune Unused Resources in Docker

Over time, Docker can accumulate unused resources like containers, images, volumes, and networks. These unused resources consume disk space and can make your Docker environment less efficient. To keep your system clean and free up disk space, it's a good practice to regularly prune these resources using Docker's built-in commands.

Here are some useful commands for resource pruning:

  • Prune Unused Containers:

    docker container prune
  • Prune Unused Images:

    docker image prune
  • Prune Unused Volumes:

    docker volume prune
  • Prune Unused Networks:

    docker network prune
  • Prune All Unused Resources (Containers, Images, Volumes, Networks):

    docker system prune

Please exercise caution when using these commands, especially the docker system prune command, as it will remove all unused resources, and there's no way to recover them once they are pruned. It's a good practice to periodically run these commands, but be mindful of their potential impact on your Docker environment.

You can also automate resource pruning by setting up a scheduled job or script to run these commands regularly. This helps maintain a clean and efficient Docker environment and can prevent unexpected resource-related issues in the future.

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