Getting cron to run on php: 7-fpm image

I'm new to docker. I installed the docker file using php: 7-fpm image. Like this image used to run my site, I want to add cron to perform common tasks.

I created cron, put it in the right folder and ran it docker exec -ti myimage_php_1 /bin/bash, then cronor, if I did tail, the log file worked fine. But I can’t get this to work when the container is created, I don’t want to manually run cron.

From what I understand, I need to use CMDor ENTRYPOINTto run the command cronat startup, but every time I do this, it stops my site due to the fact that I redefine the necessary functions of the CMD/ENTRYPOINToriginal php: 7-fpm image. Is there a way to invoke the cron command and continue as before with php: 7-fpm CMD/ENTRYPOINTs?

+4
source share
1 answer

Approach No. 1

Create your custom entrypoint.sh, something like this:

#!/bin/bash

cron -f &
docker-php-entrypoint php-fpm

Pay attention to &, this means "send to the background."

Then:

COPY ./entrypoint.sh /
ENTRYPOINT /entrypoint.sh

Approach # 2

But there is a more complicated installation method supervisor, see docs (daemon manager used in docker):

Docker:

RUN apt-get update

RUN apt-get install supervisor
COPY ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf
...
CMD ["/usr/bin/supervisord"]

supervisord.conf

[program:cron]
command = cron -f

[program:php]
command = docker-php-entrypoint php-fpm

:

docker exec <container-id> supervisorctl status
docker exec <container-id> supervisorctl tail -f php
docker exec <container-id> supervisorctl tail -f cron
docker exec <container-id> supervisorctl restart php
+5

Source: https://habr.com/ru/post/1677979/


All Articles