-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Django Crontab Job Not Executing Within Docker Container #130
Comments
This may work for you When you start your docker container, start the cron service as well.
Ref: #62 (comment) |
I tried, but does not work. |
As an alternative, do not use django-crontab Instead try this: In your Dockerfile:
before starting your container (start.sh):
Then create a manage.py command called So the cron will just call the manage command at specified intervals. |
@kazimovzaman2 |
Nope, I can't ;( |
I found a solution! update your docker files and add:
and add to entrypoint.sh touch /var/log/cron.log
printenv | grep -Ev 'BASHOPTS|BASH_VERSINFO|EUID|PPID|SHELLOPTS|UID|LANG|PWD|GPG_KEY|_=' >> /etc/environment
python manage.py crontab remove
python manage.py crontab add
service cron start This will install cron and copy all env variables to place where cron can see them. |
thanks.It has worked well for me.
to
|
It doesn't work with alpine distro neither 😞 |
@tuanhopham u saved me!!! THANKS, BRO!! |
The issue here is that cron gets its environment variables from For docker, in your entry point script just add the line If you want to verify for yourself, you can add this code to the top of your script and run it from the command line and also from cron, and compare the environment variables in both cases.
|
You saved me, thanks a lot ❤️ |
I am facing an issue with running Django crontab jobs within a Docker container. The crontab jobs work perfectly in my local development environment, but when I dockerize my Django app and attempt to run it within a container, the crontab jobs do not seem to execute as expected.
Here's a breakdown of the setup and the problem I'm encountering:
Local Development (Working): In my local development setup, I have added the following configuration to my Django settings:
This configuration sets up a crontab job that deactivates expired course enrollments. The crontab job works perfectly in this environment.
Docker Setup: To dockerize my Django app, I've created a Dockerfile and a start.sh script as part of my Docker Compose configuration:
Dockerfile:
start.sh:
The Issue: After setting up the Docker environment and running my Django app within a container, I see that the crontab job is correctly registered when I run python manage.py crontab show. However, the job does not execute as expected. Even though the job is shown as active, it doesn't run at the specified interval. The command python manage.py crontab run {cron_id} executes the job only once, but it doesn't run automatically as it should.
I have checked various aspects such as the Docker setup, the way I'm configuring the crontab job, and the interaction between Docker and the crontab service. Everything seems correct, and I'm not receiving any error messages that could point me in the right direction for debugging.
I am reaching out for help in understanding why the crontab jobs are not running as expected within the Docker container. If anyone has experience with running Django crontab jobs within a Dockerized environment and can provide insights into potential pitfalls, configuration adjustments, or troubleshooting steps, I would greatly appreciate it.
Thank you for your time and assistance.
In an attempt to resolve the issue of crontab jobs not running within the Docker container, I added the service cron start command to the start.sh script. My intention was to manually start the cron service within the container, hoping that this might trigger the execution of the crontab jobs. But does not work.
The text was updated successfully, but these errors were encountered: