2

I have installed crontabs on docker and added two users root,elasticsearch in cron.allow file line by line in /etc/cron.allow.

It's allowing me to insert cronjobs for two users root,elasticsearch.

For user root,crond start is getting started but for user elasticsearch crond is not getting started and getting error : crond: can't open or create /var/run/crond.pid: Permission denied

Here is my docker file:

FROM docker.elastic.co/elasticsearch/elasticsearch:6.6.0
ENV PATH=$PATH:/usr/share/elasticsearch/bin
RUN yum -y update
RUN yum -y install crontabs
RUN echo  "root" > /etc/cron.allow
RUN echo  "elasticsearch" >> /etc/cron.allow
RUN echo "" >> /etc/cron.allow
RUN chmod -R 755 /etc/cron.allow
RUN cd /etc/ && cat cron.allow && cat cron.deny
RUN chown -R elasticsearch /etc/cron.d
RUN chmod -R 755 /etc/cron.d
RUN chown -R elasticsearch /var/spool/cron
RUN chmod -R 755 /var/spool/cron
RUN chown -R elasticsearch /etc/crontab
RUN chmod -R 755 /etc/crontab
RUN chown -R  elasticsearch /etc/cron.d
RUN chmod -R 755 /etc/cron.d
COPY ./purge.sh  /usr/share/elasticsearch
RUN ls -l /etc/crontab
RUN ls -l /etc/cron.d
RUN   touch /usr/share/elasticsearch/cron.log
ADD ./cron /etc/cron.d/cron_test
RUN chmod 0755 /etc/cron.d/cron_test
RUN cd /etc/cron.d && cat cron_test
RUN chown -R elasticsearch /etc/cron.d/cron_test
RUN  ls -l  /etc/cron.d/cron_test
USER elasticsearch
RUN crontab /etc/cron.d/cron_test
RUN crontab -l
RUN chmod 600 /var/spool/cron/elasticsearch
ENTRYPOINT crond start && pgrep cron  && tail -f && tail -f /usr/share/elasticsearch/cron.log/usr/share/elasticsearch/cron.log
CMD elasticsearch
RUN cd /var/run && ls
EXPOSE 9200 9300

building sucessful but while running : $ docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" crontabtest crond: can't open or create /var/run/crond.pid: Permission denied

how to allow elasticsearch user to start crond service?

  • Typical cron daemons run cron jobs on behalf of all users and must run as root. "How do I configure my cron daemon" isn't generally considered a programming-related question; the [help/on-topic] has some more information. – David Maze Mar 14 '19 at 09:12
  • You also might find [this answer](https://stackoverflow.com/a/34245657/10008173) to [What is the difference between CMD and ENTRYPOINT in a Dockerfile?](https://stackoverflow.com/questions/21553353/what-is-the-difference-between-cmd-and-entrypoint-in-a-dockerfile) interesting: your Dockerfile tries to launch cron only, and the `CMD elasticsearch` will be completely ignored. – David Maze Mar 14 '19 at 09:14

0 Answers0