Running a "docker run" command via crontab does not work

  cron, docker, server, ubuntu

Everyminute ( for Testing ) I am running a cronjob to create a container, Run a nodejs process in it and then remove the container as well.

It works as expected from a regular command, but fails to produce any results or output when running via crontab.

here is my crontab

*/1 * * * * sh /location_to_cron/cron.sh >> /location_to_cron/backup.log

Here is the content of the cron shell script

CONTAINER_NAME="node_backup_repo"

echo "Creating Container to create backup, name: $CONTAINER_NAME"

docker run --name $CONTAINER_NAME -v /location_to_backup_dir:/app --dns="my_custom_dns" -w /app node:16 "backupscript.js" >> /location_to_cron/backup.log

echo "Removing container $CONTAINER_NAME"
docker rm $CONTAINER_NAME

echo "All done..."

Syslog entries indicate that the crontab is being executed as my user, which is as expected. What could be wrong here?

Source: Docker Questions

LEAVE A COMMENT