Bobcares

For every $500 you spend, we will provide you with a $500 credit on your account*

BLACK FRIDAY SPECIAL

*The maximum is $4000 in credits, Offer valid till November 30th, 2024, New Customers Only, Credit will be applied after purchase and expires after six (6) months

For every $500 you spend, we will provide you with a $500 credit on your account*

BLACK FRIDAY SPECIAL

*The maximum is $4000 in credits, Offer valid till November 30th, 2024, New Customers Only, Credit will be applied after purchase and expires after six (6) months

Crontab Docker Prune Command | Guide

by | Jul 27, 2023

Learn more about Crontab Docker System Prune command. Our Docker Support team is here to help you with your questions and concerns.

Crontab Docker Prune Command | Guide

Docker is a great tool for managing containers. However, it can also be a bit of a resource hog. If we are not careful, we are likely to end up with a lot of unused containers and images that take up space on our disks.

Crontab Docker Prune Command | Guide

Fortunately, that is where the docker system prune command comes in handy. It helps clean up these unused resources. We have to run the command as it is not done automatically.

This is why our experts recommend using cron to schedule this command. In other words, we can run the command regularly with cron. Thereby, automatically cleaning up our unused containers and images.

Let’s take a look at how to schedule it:

  • First, we have to create a new file in the /etc/cron.daily directory.
  • Then, add the following line to the file:

    #!/bin/bash
    docker system prune -af --filter "until=$((30*24))h"

    This line informs cron to run the docker system prune command with the -af and –filter flags. The -af flag tells Docker to delete all unused containers, and the –filter flag tells Docker to only delete images that are older than 30 days.

  • Next, we have to save the file and make it executable.

    sudo chmod +x /etc/cron.daily/docker-prune

  • Now, we can test the cron job as seen here:

    run-parts /etc/cron.daily

    If the cron job works correctly, we will see a message that the docker system prune command was executed successfully.

Additional Tips for Automating Docker cleanup with cron

We can use the -d flag with the docker system prune command to specify the number of days to keep unused containers and images.

Additionally, we can use the -f flag to force the docker system prune command to run even if there are no unused containers or images.

Furthermore, we can use the -l flag to list the unused containers and images before they are deleted.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

In summary, our Support Techs demonstrated how to use Crontab Docker System Prune command.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

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

Never again lose customers to poor
server speed! Let us help you.