B
B
BkackJesus2019-04-19 12:11:41
Task Schedulers
BkackJesus, 2019-04-19 12:11:41

How to run task inside docker container from host in cron?

Hello!
I want to run a task inside a docker container from a host in the cron. There is such a solution

/usr/bin/docker-compose -f ~/path/to/docker-compose.yml exec -T php /usr/bin/php /var/www/bin/yii bigquery/events
, if you just run it, it works and the task works out, but when I do all this, I put it in cron
* * * * * /usr/bin/docker-compose -f ~/path/to/docker-compose.yml exec -T php /usr/bin/php /var/www/bin/yii bigquery/events
, then nothing works. There is no information about the error in the cron logs.
What could be wrong

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BkackJesus, 2019-05-06
@BkackJesus

Answer found! And as it happens, he is banal. docker-compose didn't see the variables from the .env file. had to change directory before executing docker-compose

* * * * * cd ~/directory/to/your/docker-compose && /usr/local/bin/docker-compose -f ~/directory/to/docker-compose.yml run --rm -T -w /var/www php /var/www/bin/yii bigquery/events

S
scor2k, 2019-04-25
@scor2k

Since you're making your bike anyway, make sure that the application you're running is always running on the host and has some port published. Further - easier. From Cron, knock on this port with curl at the required frequency, and the handler from the application will already run your task.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question