简体   繁体   English

Ubuntu 16.04 Cron运行Docker容器

[英]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. 我有一个运行Ubuntu 16.04的虚拟机,我想在该虚拟机上运行cron调度的Docker容器。 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. 我已经配置了Docker主机和映像存储库,以使VM可以访问它们,并且映像在计算机上运行良好。

My issue is that when I create a cron-schedule using crontab -e in /var/spool/cron , the containers do not show up. 我的问题是,当我在/var/spool/cron使用crontab -e创建cron计划时,容器不会显示。 I should be able to view any stopped containers using $ docker ps -a , but it does not show them. 我应该能够使用$ docker ps -a查看任何已停止的容器,但不会显示它们。 Running sudo grep CRON -i /var/log/syslog shows the output: 运行sudo grep CRON -i /var/log/syslog显示输出:

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) . 现在,按照调试的时间表,它确实每2分钟运行一次,但是docker ps -a什么也不显示,即使容器应该已经退出,因此应该闲置,直到我使用docker rm $(docker ps -aq)为止。 Has anyone seen this problem before? 有人看过这个问题吗?

Here is my job configured in crontab: 这是我在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. 注意:我尚未创建要输出到cronjobs的邮件设置,因此No MTA...错误,并且我正在Ubuntu VM上而不是Ubuntu docker基础映像上运行此设置。

Found my problem. 发现我的问题。 When I was originally troubleshooting using grep, my search was omitting a fairly important piece of the log stream. 当我最初使用grep进行故障排除时,我的搜索忽略了日志流中相当重要的部分。 So by using vim to view /var/log/syslog : 因此,通过使用vim查看/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. 我在crontab文件中犯了拼写错误,因此docker守护程序无法找到该映像,从而导致此问题。

Chalk it up to amateur hour 将其归纳为业余时间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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