0

This is my Dockerfile

FROM php:7.4-fpm-alpine

COPY / /var/www/

RUN apk update &&  apk add php libraries ..

WORKDIR /var/www

# add the crons
RUN mkdir /etc/periodic/minutely
COPY docker/crons/minutely/crons.sh /etc/periodic/minutely/crons.sh
RUN chmod -R 0755 /etc/periodic/minutely
RUN chmod +x   /etc/periodic/minutely/crons.sh
RUN (crontab -l 2>/dev/null; echo "* * * * * cd /etc/periodic/minutely && sh crons.sh")| crontab -
RUN crond start

EXPOSE 9000

This won't start crond but if I ssh to the container after it starts running and run crond start again, everything works fine, why?

Lynob
  • 5,059
  • 15
  • 64
  • 114
  • A container usually only runs one process; `RUN` commands that start background processes aren't persisted in the image. The `php:fpm` base image will run _only_ `php-fpm` as the main container process. (Do you need a separate container to run the cron service?) – David Maze Jul 20 '21 at 15:24
  • @DavidMaze the cron service is a PHP script that needs `php-fpm` to run, what to do is that case? – Lynob Jul 20 '21 at 15:33
  • Run a second container, from the same image, that runs the cron daemon as a foreground process as its main command. – David Maze Jul 20 '21 at 15:44
  • My question got closed, but the suggested solution does not answer my question, I was in the process of writing an answer before it got closed, in any case, [this answers my question](https://www.cloudsavvyit.com/9033/how-to-use-cron-with-your-docker-containers). in `docker-compose.yml`: `entrypoint: /usr/sbin/crond` and `command: ["start", "-f"]`. To whoever decided to close my question, that question you picked is number one on google, so if it solved the problem at hand I wouldn't have asked, but it's useless, at least in my usecase. – Lynob Jul 20 '21 at 17:30

0 Answers0