Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cron.d中的cron不会在Docker容器中运行的Ubuntu上运行_Ubuntu_Docker_Amazon Ec2_Cron_Ubuntu 16.04 - Fatal编程技术网

cron.d中的cron不会在Docker容器中运行的Ubuntu上运行

cron.d中的cron不会在Docker容器中运行的Ubuntu上运行,ubuntu,docker,amazon-ec2,cron,ubuntu-16.04,Ubuntu,Docker,Amazon Ec2,Cron,Ubuntu 16.04,我写了一个非常小的程序,主要由刮泥器组成。我把它包装在一个docker容器中,需要cron调用scraper 我的docker撰写文件是: version: '2' services: admin-panel: env_file: ./Admin-Panel/.env build: ./Admin-Panel/ volumes: - ./Admin-Panel/app:/code/app - ./Admin-Panel/flaskadmin.p

我写了一个非常小的程序,主要由刮泥器组成。我把它包装在一个docker容器中,需要cron调用scraper

我的docker撰写文件是:

version: '2'
services:
  admin-panel:
    env_file: ./Admin-Panel/.env
    build: ./Admin-Panel/
    volumes:
      - ./Admin-Panel/app:/code/app
      - ./Admin-Panel/flaskadmin.py:/code/flaskadmin.py
    ports:
      - "5000:5000"
  scraper:
    env_file: ./Admin-Panel/.env
    build: ./Scraper/
    volumes:
      - ./Scraper/spiders:/spiders
我的文档是:

FROM ubuntu:latest
ENV TERM xterm

RUN apt-get update
RUN apt-get install -y python3-pip python3.5-dev build-essential  
RUN apt-get install -y libssl-dev nano cron libpq-dev libffi-dev curl

ADD ./requirements /requirements
ADD crontab /etc/cron.d/scrapers

RUN pip3 install --upgrade pip
RUN pip3 install -r /requirements/base.txt

RUN touch /var/log/cron.log

CMD cron && tail -f /var/log/cron.log
我的crontab后面有一个新行:

* * * * * root /usr/local/bin/scrapy runspider /spiders/myspider.py
* * * * * root /bin/date >> /tmp/cron_output
当在运行Sierra的Mac上本地运行时,这种方法非常有效,但是当我在运行AmazonLinuxAMI的AmazonEC2实例上运行时,cron不会被调用。我使用Filezilla将文件从Mac传输到AmazonEC2实例

AWS EC2:

Docker版本1.12.6,构建7392c3b/1.12.6

我的MacBook:

Docker版本17.03.0-ce,版本60ccb22

如果我加一行

* * * * * root /bin/date >> /tmp/cron_output
使用crontab-e也不会发生任何事情。文件cron.log为空

更新:

我安装了rsyslog,然后启动了它:

service rsyslog start
现在在/var/log/syslog中

Mar 25 21:49:01 4406b0e05b9f CRON[464]:无法为指定会话创建/删除条目


尝试向Dockerfile添加权限,例如

运行chmod 0744/spider/myspider.py/etc/cron.d/scrapercron

并更改crontab的位置

添加scrapercron/etc/cron.d

然后在你的crontab中

HOME=/spider *****根/spider/myspider.py>>/tmp/cron_输出2>&1

要进行测试,请尝试输出到该tmp文件


CMD cron&&tail-f/tmp/cron_输出

多亏了

我在/etc/pam.d/cron中注释掉了下面一行

session    required     pam_loginuid.so

只需解决如何在docker compose up上自动执行此操作。

docker容器不会运行全套服务。很有可能crond根本就没有在您的容器中运行,除非您已经显式地将其配置为这样做?