N
N
NkDev2018-03-21 15:39:19
linux
NkDev, 2018-03-21 15:39:19

How to make a bundle in Docker: php + cron?

In Docker, you need to make sure that the php script is run in cron once a day. Can you tell me how to implement it correctly? On the Internet, I met the option to run 2 processes at once in one container via supervisor (fpm and cron), but others say that each process should be isolated. I also met another option, when something in the spirit of docker exec php /path/to/php/script.php is written to the cron in the host system, but this looks a lot like a crutch. I created 2 containers: in one php in another cron. I linked them using links and volumes, but I can't call a php script from another container from the php cron. Tell me how to do it right?
docker-compose.yml file

cron:
    build: ./
    links:
        - "php"
    volumes:
        - "./:/home"

php:
    image: php
    command: tail -f /dev/null
    volumes:
        - "./:/home"

Dockerfile
FROM centos
RUN yum -y update
RUN yum -y install crontabs
RUN sed -i -e '/pam_loginuid.so/s/^/#/' /etc/pam.d/crond
ADD cron /etc/cron.d/cron_test
RUN chmod 0644 /etc/cron.d/cron_test
RUN crontab /etc/cron.d/cron_test
CMD crond && tail -f /dev/null

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ice2038, 2018-03-21
@NkDev

There is absolutely no need to create a separate cron container, it makes no sense. It is enough to describe all the tasks in the layer above

* * * * * docker run --rm your-container /home/user/task.sh

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question