Over time, Docker may accumulate a significant amount of unused build cache, which can consume valuable disk space. This can lead to storage issues, especially on systems with limited disk space.

To free up disk space taken by Docker’s build cache, you can use the following command. This command will remove all unused build cache. Please note that running this command will not remove any images, containers, volumes, or networks that are in use by running containers or are tagged.

Procedure:

  1. Open a terminal on the host where Docker is running.
  2. Run the following command to remove unused build cache
docker builder prune

3. Docker will prompt you to confirm the removal of the build cache. Type y and press Enter to proceed.

4. If you want to remove the build cache without a confirmation prompt, you can use the -f or --force flag:

docker builder prune -f

5. To remove build cache and also include stopped build containers and build cache for all builders, use the -a or --all flag:

docker builder prune -a

6. To remove only the build cache that hasn’t been used within the last 24 hours, you can use the --filter flag with the until parameter:

docker builder prune --filter "until=24h"

7. After running the command, Docker will display the amount of disk space reclaimed.

8. It’s a good practice to run docker builder prune periodically to keep your system clean and ensure that disk space is not being wasted on unused build cache.

Additional Information:

  • Be cautious when using docker builder prune, especially with the --all flag, as it may remove more than just the unused build cache.
  • You can also schedule a cron job to run this command periodically if you find that your build cache grows quickly.
  • Always make sure that you are not in the middle of a build process when running this command to avoid any potential disruption.

#docker #diskspace #kubernetes #devops #project


Discover more from Tech Insights & Blogs by Rahul Ranjan

Subscribe to get the latest posts sent to your email.

Leave a comment

Trending