Removal of unused Docker images

During the service upgrade, new Docker image is downloaded. However, the original image is retained on the filesystem, taking up space Therefore, these old images should be removed. A prepared service can be used to do that. This service simply runs the command docker image prune -a -f which removes all images for which there is no corresponding container at the moment.

Configuration of the scheduled task

Jobs for removing unused Docker images are prepared in the IAM appliance and they only need to be activated using the systemd units.

  • iam-docker-images-prune.service - A service which removes unused Docker images.

  • iam-docker-images-prune.timer - The configuration of the scheduled task; the interval in which iam-docker-images-prune.service should be run.

State of the unused Docker images removal job

The state of the planned task can be found out using these commands:

[root@localhost ~]# systemctl status iam-docker-images-prune.service
[root@localhost ~]# systemctl status iam-docker-images-prune.timer
[root@localhost ~]# systemctl list-timers --all

Activating scheduled tasks

To activate the planned tasks, run the timer and activate its automatic start after the OS start. Deactivate it the same way, only using the stop, and disable commands.

[root@localhost ~]# systemctl start iam-docker-images-prune.timer
[root@localhost ~]# systemctl enable iam-docker-images-prune.timer

By default, this task is run once a week outside of work hours.

You can also remove unused Docker images manually by running the service iam-docker-images-prune.service.