Sunday, June 11, 2017

Cronjob on any server for removing docker images

1)We need to check with the crontab -l,whether you have the cron for that particular user,this is an example:

crontab -l
example:(no crontab for ubuntu).

2)This command will open the crontab in a text editor:
 crontab -e

#Remove's the Docker Images
03 21 * * * /bin/docker rmi $(docker images -a -q) | /home/user/datelog.sh >>/home/user/docker-rmcron.log 2>&1
enter this information and save it.

3)In the datelog.sh,this particular script will help us to get the information with the dataformat and the script we included in this file:
     while IFS= read -r line; do printf '[%s] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$line"; done

Path
/home/user/datelog.sh

4)The cronjob is on "user" user and the logs are stored in this path:

Path
/home/user/docker-rmcron.log
user may be ec2-user,centos etc


No comments:

Post a Comment