We use Docker containers inside build pipelines in Azure DevOps. The images are pulled from an Artifactory Docker repository. While the Docker containers only exist while the pipeline is running, the images remain on the build agent.
For my understanding the release retention does not affect the pulled Docker images. Is there any best practice to automatically clean up older Docker images in Azure DevOps depending on the date or how much space they take? Or do I have to use a cron job with docker prune?
We use the on premise solution of Azure DevOps.
There is no built-in way to automatically clean up older Docker images in Azure DevOps on-premises. However, there are few workaround that you can follow:
Use a cron job with the docker prune command. Open the crontab file for the user that runs the Docker containers. You can use the command
crontab -eto open the crontab file. Add a new line to the crontab file with the docker prune command. For example, you can use the following command to remove all unused Docker images and containers every day at midnight, 00:00, 01:00, 02:00, and so on, every day. The-afflags telldocker system pruneto remove all unused images, including images that are dangling, untagged, or tagged with a tag that does not exist.Save the crontab file and exit. This cron job will run every day at midnight and remove all unused Docker images and containers. You can adjust the frequency of the cron job and the options for the docker prune command as needed.
Another workaround is you can use custom script to automatically remove unused images.
Prune unused docker objects
Auto-cleanup using custom script