Hi Ken, sww314,
Thank you both for your replies. As always, people here are often very generous with their time and answers.
So, my problem was a dumb problem and simply a misconfiguration in my celerybeat
configuration. I had DJANGO_SETTINGS_MODULE="config"
instead of
DJANGO_SETTINGS_MODULE="config.settings"
.
After jumping over that hurdle, I managed to fire up celery in my Django container without fuss using init.d.
After reading Ken’s post, I was curious about how Django in one container could use Celery in another container. I admit, I still do not know the answer to this, and I’ll have to dig deeper, but I did find this cheat sheet for Dokku (which I use) which showed how to use the Procfile
to launch other containers for use in the same codebase.
The link which provided the answer is https://cheat.readthedocs.io/en/latest/django/dokku.html#running-other-daemons-like-celery
In essence, if I add the following to my procfile, Dokku will fire up Docker instances of Celery Beat and Celery Workers. From what I understand it is better practice, and something Ken alluded to, to have a single service running in a docker container rather than trying to fit multiples services in a single Docker container.
If one searches Google or Duck Duck Go for help for Django + Celery + Docker, you’ll find many articles showing how it is done with Docker Compose, but none addressing the concept of deployment. The above link addresses deployment, but only with Dokku
Should someone stumble across this post looking for firing up Celery with Django in a single container, then adding the following in the Docker file and the following celerybeat
file should help them on their way.
Dockerfile additions for celery beat
COPY misc/celery/celerybeat-init /etc/init.d/celerybeat
COPY misc/celery/celerybeat /etc/default/celerybeat
COPY misc/celery/celerybeat /etc/default/celeryd
RUN chmod 755 /etc/default/celerybeat
RUN chmod 755 /etc/init.d/celerybeat
RUN adduser --disabled-password --gecos "" celery
Celerybeat config file
Be sure to replace my config.settings
with your project name and settings file.
# Absolute or relative path to the 'celery' command:
CELERY_BIN="/usr/local/bin/celery"
# App instance to use
# comment out this line if you don't use an app
CELERY_APP="config"
export DJANGO_SETTINGS_MODULE="config.settings"
DJANGO_SETTINGS_MODULE="config.settings"
# Where to chdir at start.
CELERYBEAT_CHDIR="/code/"
CELERYD_CHDIR="/code/"
CELERYD_USER="celery"
CELERYD_GROUP="celery"
CELERYBEAT_USER="celery"
CELERYBEAT_GROUP="celery"
# Extra arguments to celerybeat
CELERYBEAT_OPTS="--schedule=/var/run/celery/celerybeat-schedule"