Docker Community Forums

Share and learn in the Docker community.

Apache + crontab centos


(Royalland123) #1

have a problem i can not make crontab work. it is installed correctly but it does not turn.

here is my dockerfile:

FROM s2144tds.mc2.xxxxx.fr:5000/bases-ope/php:5.6

ARG TAG_GIT="not define"

LABEL maintainer_name="xx.xx-extern@xxx.com"
LABEL maintener_mail="<xx.xx-extern@xxx.com>"
LABEL description="xx-xx-bdl"
ENV VERSION=${TAG_GIT}
LABEL TAG_GIT=${TAG_GIT}

COPY ./src /sources/.
RUN yum -y install cronie
RUN crond -s
EXPOSE 8082
USER apachephp
ENTRYPOINT [ "/usr/local/apache2/bin/httpd" ]
CMD [ "-D", "FOREGROUND" ]

I run the page crontab.php

$txt = "*/1 * * * * ls >> /tmp/log.txt  \n";
exec('crontab -r');

file_put_contents('/tmp/crontab.txt', $txt);
exec('crontab /tmp/crontab.txt');

exec("crontab -l ", $output, $result);


var_dump( $output);

it works well but the crontab does not launch

Thank you for your help.


(Martin Terp) #2

Hi

Its because you have the cron deamon, in the dockerfile, this will only run, on build of the image, and not as a process in the container.

If you want to have 2 services to run at the same time, apache and cron, take a look at this


(Royalland123) #3

Continuing the discussion from Apache + crontab centos:

Finaly

Solution just add this :

COPY ./src /sources/.
RUN yum -y install crontabs
RUN sed -i -e '/pam_loginuid.so/s/^/#/' /etc/pam.d/crond
RUN chmod 0644 /etc/crontab
CMD crond && tail -f /dev/null

EXPOSE 8082
USER apachephp
ENTRYPOINT [ "/usr/local/apache2/bin/httpd" ]
CMD [ "-D", "FOREGROUND" ]