Answer the question
In order to leave comments, you need to log in
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. Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question