Is it possible to get cron to work without destroying Docker?

  • Issue type
    Read below and you’ll understand.

  • OS Version/build
    Host = Arch Linux
    Container = Debian 10.9

  • App version
    Docker version 20.10.12, build e91ed5707e

  • Steps to reproduce
    Put whatever I described below in the Dockerfile file, and then “sudo docker-compose down --rmi all --volumes --remove-orphans && sudo docker-compose up -d && sudo docker-compose exec app bash”.

I might come over as a rant, but this is yet another Docker-specific issue I can’t wrap my head around.

In the Dockerfile, I have to add a crontab and then execute cron.
However, if I use “CMD cron”, “sudo docker-compose exec app bash” does absolutely nothing, and the webpage gives me “ERR_CONNECTION_REFUSED”.
If I use “CMD [“cron”,”-f", “-l”, “2”]", I can get into the Docker container and cron is doing its job, this time the webpage gives me a “502 Bad Gateway” error.
If I don’t use the CMD command at all, the warning doesn’t show up, the webpage loads as it should, but cron never gets executed.

So is there some way to get cron to work while keeping the webpage functional?
I want to have both, not either one or the other.

Thanks.

Edit:
As if it couldn’t get any more broken.
Despite clearly stating to put “/usr/local/bin/php” into the crontab, it still puts “php” instead.
Lovely how modern technology never works…

Edit 2:
I ended up explaining to everyone to manually add a line to their crontabs and start the service manually, because at least that way the whole web app doesn’t get destroyed and the crontab gets set up properly too.

Once again, very disappointed at modern technology and the modern web as a whole.

Hi

I havnt looked into this for a while, but a solution to your problem could be to use supervisor, then you set supervisor as your CMD and let it spawn cron and php, it can also send all outputs to stdout

Found an old post where i give a quick example: