Docker CentOS 7 - cron不能在本地机器上工作 [英] Docker CentOS 7 - cron not working in local machine

查看:355
本文介绍了Docker CentOS 7 - cron不能在本地机器上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的VPS中,我创建了一个包含cron作为入口命令运行的docker镜像。我也有一个示例cron文件,说它应该每5分钟执行一次命令。



Dockerfile:

  FROM centos:centos7 
MAINTAINER Lysender< foo@example.com>

#安装软件包
RUN yum -y update&& yum clean all
RUN yum -y安装epel-release&& yum clean all

RUN yum -y install git \
bind-utils \
pwgen \
psmisc \
net-tools \\ \\
hostname \
curl \
curl-devel \
sqlite \
cronie \
libevent \
gearmand \
libgearman \
libgearman-devel \
php \
php-bcmath \
php-common \
php-pear \
php-mysql \
php-cli \
php-devel \
php-gd \
php-fpm \
php-pdo \
php-mbstring \
php-mcrypt \
php-soap \
php-xml \
php-xmlrpc \\ \\
php-pecl-gearman&& yum clean all

#配置服务
ADD ./start.sh /start.sh
ADD ./my-cron.conf /etc/cron.d/my-cron

RUN chmod 755 /start.sh

CMD [/ bin / bash,/start.sh]



my-cron.conf文件:

 每5分钟运行一次命令
* / 5 * * * * root echofoo>> /tmp/logit.log 2>& 1

start.sh

 #!/ bin / bash 

__run_cron(){
echo运行run_cron函数。
crond -n
}

#调用所有函数
__run_cron

然后我这样构建:

  docker build --rm -t lysender / cron- php-gearman。 

然后运行:

  docker run --name cron -d lysender / cron-php-gearman 

5分钟后,我检查了cron是否工作:

  docker exec -it cron bash 
cat / tmp / logit .log

  docker push lysender / cron-php-gearman 

code>

然后拉入我的本地计算机并像我在VPS主机上一样运行它。



但是,没有迹象表明cron实际运行,例如: /tmp/logit.log 文件从未创建。



可能出现什么错误?



机器规格:




  • 本地:VirtualBox虚拟机运行Slackware 14.1,Docker 1.6.2 - 与VPS相同
  • VBS:Linode在KVM,Docker 1.6.2上运行Slackware 14.1


两者都作为普通用户(非root用户)运行。



但是,区别是CentOS镜像。




  • VPS:5周




  • <两个都是5周老,但我没有删除的图像第一(只是更新/拉)。



    所以我拉CentOS 7,然后pull lysender / cron-php-gearman。我的理解是,它应该运行在更新的CentOS 7镜像之上。

    解决方案

    我决定不使用库存daemon并基于此Dockerfile切换到基于python的 devcron



    https://registry.hub.docker.com/u/hamiltont/docker-cron/dockerfile/



    这是我的新Dockerfile。



    https://github.com/lysender/docker-cron-php-gearman/blob/master/Dockerfile



    Devcron: https://bitbucket.org/dbenamy/devcron



    原因是,在清除整个本地泊坞窗安装和安装新的docker镜像之后,股票cron在我的本地设置中仍然不工作。



    这将是我暂时的解决方案。



    感谢您的帮助。


    In my VPS, I have created a docker image containing cron running as entry command. I also have a sample cron file that says it should execute the command every 5 minutes.

    Dockerfile:

    FROM centos:centos7
    MAINTAINER Lysender <foo@example.com>
    
    # Install packages
    RUN yum -y update &&  yum clean all
    RUN yum -y install epel-release && yum clean all
    
    RUN yum -y install git \
        bind-utils \
        pwgen \
        psmisc \
        net-tools \
        hostname \
        curl \
        curl-devel \
        sqlite \
        cronie \
        libevent \
        gearmand \
        libgearman \
        libgearman-devel \
        php \
        php-bcmath \
        php-common \
        php-pear \
        php-mysql \
        php-cli \
        php-devel \
        php-gd \
        php-fpm \
        php-pdo \
        php-mbstring \
        php-mcrypt \
        php-soap \
        php-xml \
        php-xmlrpc \
        php-pecl-gearman && yum clean all
    
    # Configure servicies
    ADD ./start.sh /start.sh
    ADD ./my-cron.conf /etc/cron.d/my-cron
    
    RUN chmod 755 /start.sh
    
    CMD ["/bin/bash", "/start.sh"]
    

    my-cron.conf file:

    # Run command every 5 minutes
    */5 * * * * root echo "foo" >> /tmp/logit.log 2>&1
    

    start.sh

    #!/bin/bash
    
    __run_cron() {
        echo "Running the run_cron function."
        crond -n
    }
    
    # Call all functions
    __run_cron
    

    Then I build it like this:

    docker build --rm -t lysender/cron-php-gearman .
    

    Then run:

    docker run --name cron -d lysender/cron-php-gearman
    

    After 5 minutes, I checked if the cron works:

    docker exec -it cron bash
    cat /tmp/logit.log
    

    It works. So I pushed it to docker hub into my account.

    docker push lysender/cron-php-gearman
    

    Then pull in my local machine and run it like how I did on my VPS host.

    However, there is no sign that the cron actually runs, ex: /tmp/logit.log file is never created.

    What could have been wrong?

    Machine specs:

    • VPS: Linode running Slackware 14.1 on KVM , Docker 1.6.2
    • Local: VirtualBox VM running Slackware 14.1, Docker 1.6.2 - same as the VPS

    Both are run as regular user (non-root).

    However, the difference is the CentOS image.

    • VPS: 5 weeks old
    • Local: 4 months old.

    I have pulled a new CentOS7 image so that both would be 5 weeks old but I didn't delete the image first (just updated/pulled).

    So I pulled CentOS 7, then pull lysender/cron-php-gearman. My understanding is that it should be running on top of the newer CentOS 7 image.

    解决方案

    I have decided to not use stock cron daemon and switch to a python based devcron based on this Dockerfile.

    https://registry.hub.docker.com/u/hamiltont/docker-cron/dockerfile/

    Here is my new Dockerfile.

    https://github.com/lysender/docker-cron-php-gearman/blob/master/Dockerfile

    Devcron: https://bitbucket.org/dbenamy/devcron

    The reason is that, after wiping out the whole local docker installation and installing fresh docker images, the stock cron is still not working in my local setup.

    This will be my temporary solution for now.

    Thanks for the help.

    这篇关于Docker CentOS 7 - cron不能在本地机器上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆