Dockerfile image:
FROM webdevops/php-apache-dev:7.4 Tạo cron trong webdevops: tạo file supervisor-cron.php trong project:
[group:cron]
programs=crond
priority=25
[program:crond]
command = /opt/docker/bin/service.d/cron.sh
process_name=%(program_name)s
startsecs = 0
autostart = true
autorestart = true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:fullpageclear]
command=bash -c 'sleep 10 && exec /usr/local/bin/php /wordpress/web/wp/wp-cron.php'
autorestart=true
Sau đó mount nó trong docker-compose.yml như sau:
- ./supervisor-cron.conf:/opt/docker/etc/supervisor.d/cron.conf Ok. Bây giờ bạn có thể chạy cron okie rồi đó. Lưu ý: Ở trên là sleep 10, nghĩa là 10 giây nha. Nếu muốn test thử trên container docker, có thể copy đoạn code trên vào /opt/docker/etc/supervisor.d/cron.conf Sau đó gõ: supervisorctl Rồi gõ reload , ấn y để chọn Yes. Vậy là nó đã reload. Để biết reload hay chưa, gõ lại: supervisorctl sẽ hiển thị danh sách các cron đang chạy. Chúc thành công.