简体   繁体   中英

Ubuntu 16.04 Cron to run Docker container

I have a virtual machine running Ubuntu 16.04 that I want to run cron-scheduled Docker containers on. I have configured the Docker host and my image repository such that they are accessible by the VM, and images run fine on the machine.

My issue is that when I create a cron-schedule using crontab -e in /var/spool/cron , the containers do not show up. I should be able to view any stopped containers using $ docker ps -a , but it does not show them. Running sudo grep CRON -i /var/log/syslog shows the output:

Mar 20 16:22:01 SpacyVM CRON[121879]: (bdsadmin) CMD (docker run -d 
bdsdev.azurecr.io/crawler-public)
Mar 20 16:22:05 SpacyVM CRON[121878]: (CRON) info (No MTA installed, 
discarding output)
Mar 20 16:24:01 SpacyVM CRON[124254]: (bdsadmin) CMD (docker run -d 
bdsdev.azurecr.io/crawler-public)
Mar 20 16:24:02 SpacyVM CRON[124253]: (CRON) info (No MTA installed, 
discarding output)

Now, this does run every 2 minutes, per the schedule for debugging purposes, but docker ps -a shows nothing, even though the containers should have exited and thus should be idle until I use docker rm $(docker ps -aq) . Has anyone seen this problem before?

Here is my job configured in crontab:

*/2 * * * * docker run -d bdsdev.azurecr.io/crawler-public

Note: I have not created a mailing setup for the cronjobs to output to, hence the No MTA... error, and I am running this in an Ubuntu VM, not on an Ubuntu docker base image.

Found my problem. When I was originally troubleshooting using grep, my search was omitting a fairly important piece of the log stream. So by using vim to view /var/log/syslog :

Mar 20 06:34:01 SpacyVM dockerd[1469]: time="2018-03-20T06:34:01.634861659Z" level=info msg="Attempting next endpoint for pull after error: manifest unknown: manifest unknown"

I had made a spelling error in my crontab file, so the image is not able to be located by the docker daemon, causing this problem.

Chalk it up to amateur hour

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM