webdevops / php-docker-boilerplate

:stew: PHP Docker Boilerplate for Symfony, Wordpress, Joomla or any other PHP Project (NGINX, Apache HTTPd, PHP-FPM, MySQL, Solr, Elasticsearch, Redis, FTP)
https://webdevops.io/projects/php-docker-boilerplate/
MIT License
562 stars 186 forks source link

How to use crontab #82

Closed nicklog closed 5 years ago

nicklog commented 5 years ago

Hey guys,

i like this boilerplate but i dont know to configure crontab.

I read the issues here in the repo but i dont get it to work and i didnt find any logs.

i tried these 4 variants

# m h  dom mon dow  user  command
*/10 * * * * application . ~/.profile; /usr/local/bin/php /app/bin/console app:proxy:import
* * * * * application . ~/.profile; /usr/local/bin/php /app/bin/console app:proxy:check
*/5 * * * * application . ~/.profile; /usr/local/bin/php /app/bin/console app:haproxy:dump
# m h  dom mon dow  user  command
*/10 * * * * application /usr/local/bin/php /app/bin/console app:proxy:import
* * * * * application /usr/local/bin/php /app/bin/console app:proxy:check
*/5 * * * * application /usr/local/bin/php /app/bin/console app:haproxy:dump
# m h  dom mon dow  user  command
*/10 * * * * /usr/local/bin/php /app/bin/console app:proxy:import
* * * * * /usr/local/bin/php /app/bin/console app:proxy:check
*/5 * * * * /usr/local/bin/php /app/bin/console app:haproxy:dump
# m h  dom mon dow  user  command
*/10 * * * * php /app/bin/console app:proxy:import
* * * * * php /app/bin/console app:proxy:check
*/5 * * * * php /app/bin/console app:haproxy:dump

What is wrong? Can anyone please help?

Thank you very much.

htuscher commented 5 years ago

Full example: Dockerfile

FROM webdevops/php-nginx:7.2
RUN docker-service-enable cron
COPY etc /opt/docker/etc

etc/cron/crontab

SHELL=/bin/bash

# m h dom mon dow   user   command
* * * * * application /usr/local/bin/php /app/bin/console sw:cron:run

The logs are redirected to stdout by supervisord (which runs all applications in the container). Therefore you're able to see the cron logs by doing docker logs -f app_container.
For production context you can e.g. use logstash to extract the cron logs from the docker log stream and show them separately.

abagayev commented 4 years ago

Hey, I just created an example of how to use crontab with webdevops docker-compose, you can check it our here: https://github.com/abagayev/docker-bootstrap-collection/tree/master/crontab-in-container