crontab not working ubuntu 16.04 crontab not working ubuntu 16.04 docker docker

crontab not working ubuntu 16.04


Docker is an application isolation tool, unlike how virtual machines are an OS isolation tool. That means you run your application inside of a Docker container, and in that container no other OS services components are running by default. So if you configure your crontab, you don't have the cron daemon running that would process that file and kick off the jobs. To have this run for you, a cron -f needs to be run to launch the daemon in the foreground. If your container runs another application (most likely), then you'd need a tool like supervisord to launch multiple applications to also run cron.


Edit: this is my attempt to reproduce your error in my lab after starting cron. As you can see, the file is created for me:

$ docker run -it --rm ubunturoot@f2e78e1bacde:/# ( apt-get update && apt-get install cron ) >/install.log 2>&1root@f2e78e1bacde:/# service cron start * Starting periodic command scheduler root@f2e78e1bacde:/# mkdir -p /var/www/publicroot@f2e78e1bacde:/# crontab - <<EOF> * * * * * echo "Run this command every minute" >> /var/www/public/cronfile.log> EOFroot@f2e78e1bacde:/# crontab -l* * * * * echo "Run this command every minute" >> /var/www/public/cronfile.logroot@f2e78e1bacde:/# ls -al /var/www/publictotal 12drwxr-xr-x 2 root root 4096 Sep  7 11:54 .drwxr-xr-x 3 root root 4096 Sep  7 11:53 ..-rw-r--r-- 1 root root   30 Sep  7 11:54 cronfile.logroot@f2e78e1bacde:/# dateWed Sep  7 11:54:18 UTC 2016root@f2e78e1bacde:/# ls -l /var/spool/cron/crontabs/total 4-rw------- 1 root crontab 255 Sep  7 11:53 rootroot@f2e78e1bacde:/#