Problem(May be): The CMD instruction in your docker file executes commands sequentially. Since runserver runs indefinitely and the command process_tasks never gets a chance to start.
The problem you are facing right now with django-background-tasks not starting automatically in the docker container due to the background work.Your current approach with CMD might not be the optimal solution and you could try some alternatives like:
If I were in your problem then I would choose supervisor or celery to run the background task simultaneously.
1. Supervisor: You have to install process manager like supervisor in your docker container.Supervisord will ensure both runserver and process_tasks run in the background simultaneously.
RUN pip install supervisor # Supervisor configuration COPY supervisord.conf /etc/supervisor/conf.d/ CMD ["supervisord", "-n"]
N.B: You have to create supervisord.conf file with configurations for both runserver and process_tasks. You can google it for this.
2. Celery: Django background tasks can be integrated with Celery, a powerful distributed task queue. It offers more features and control over background processing but requires additional configurations.
I hope you will get some ideas to solve this problem. I hope you will enjoy Python/Django ecosystem :)
Ref:
- https://imamhossainroni.me/supercharge-your-process-management-using-supervisor
- http://supervisord.org/configuration.html
- Python/django application not running with supervisord