How to create a crontab file for user elasticsearch

I want to run a crontab job on elastic search docker image

here is my docker file


ENV PATH=$PATH:/usr/share/elasticsearch/bin

RUN yum -y update

RUN yum -y install crontabs

RUN echo -e "root\nelasticsearch" > /etc/cron.allow

RUN echo "" >> /etc/cron.allow

RUN chmod -R 644 /etc/cron.d

RUN cat /etc/cron.allow

RUN chown -R elasticsearch /etc/cron.d

RUN chmod -R 755 /etc/cron.d

RUN chown -R elasticsearch /var/spool/cron

RUN chmod -R 744 /var/spool/cron

RUN chown -R elasticsearch /etc/crontab

RUN chmod -R 744 /etc/crontab

RUN chown -R elasticsearch /etc/cron.d

RUN chmod -R 744 /etc/cron.d

COPY ./ /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 0644 /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

#This will add it to the cron table (crontab -e)

RUN crontab /etc/cron.d/cron_test

RUN crontab -l

RUN cd /var/spool/cron && ls

USER elasticsearch

ENTRYPOINT elasticsearch

CMD crond start && pgrep cron && tail -f && tail -f /usr/share/elasticsearch/cron.log

EXPOSE 9200 9300](http://)

after running this docker file and executing the container

in this step in docker file
RUN cd /var/spool/cron && ls

it's showing only root , but how can i get elasticsearch user in it ?

my cron file present locally
*/1 * * * * echo "Hello world" >> /usr/share/elasticsearch/cron.log
*/1 * * * * elasticsearch /usr/share/elasticsearch/

my file
curl -XPOST "http://localhost:9200/hydro_dashboard_index/_delete_by_query" -H 'Content-Type: application/json' -d'
"query": {
"range" : {
"query_service_entry_time" : {
"lt" : "now-14d"

Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:


This is the icon to use if you are not using markdown format:

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
Please update your post.

I believe that your question is more a Docker question than an elasticsearch question. In which case I'd suggest asking in Docker forums instead.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.