Docker cron

Docker cron
Photo by Agê Barros / Unsplash

I created a multi-arch Docker image that uses cron to execute commands at specific times. The image includes the docker-cli alpine package, so mapping the docker socket to the container will allow scheduling docker commands.

For example, once a week prune images not used in the last week (168 hours):

docker run -d \
    -e WEEKLY="docker image prune -a -f --filter \"until=168h\"" \
    -v /var/run/docker.sock:/var/run/docker.sock \
    --name image-prune \
    64bitint/cron

Or to restart a container named backup-db every day at 1AM EST:

docker run -d -e T0100="docker restart backup-db" \
    -v /var/run/docker.sock:/var/run/docker.sock \
    --name restart \
    64bitint/cron

For more details checkout the docker-cron github repo.