B
B
blohinn2018-11-16 20:51:18
Django
blohinn, 2018-11-16 20:51:18

How to integrate Django Channels into Django using docker?

Let's say we have an existing Django project.
Raised by Docker, WSGI server - GUNICORN.
NGINX gives statics, everything is classic. The site is a typical blogger, etc.
Now you need to file the chat and notification system using Django Channell, deploying it through Daphne.
How to arrange all this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
neatsoft, 2018-11-17
@neatsoft

There are two options:
1. If the load is small, you can use Daphne for both WSGI and ASGI queries;
2. Pass the operating mode to containers via environment variables (use an entrypoint script that will run manage.py runserver, uwsgi, gunicorn, daphne, or manage.py runworker depending on the selected mode), distribute requests between containers depending on the path or domain name.
"According to the classics" statics are given not by Nginx, but by S3 - AWS or its analogues in production, Minio in dev environments.
Instead of Nginx, I advise you to use Traefik - it can find containers and route requests to them depending on the parameters specified in docker-compose.yml. Automatic load balancing, letsencrypt without unnecessary gestures, very easy to configure, can serve several different projects without additional settings (relevant for freelancers).

#!/bin/sh

set -o errexit
set -o pipefail
set -o nounset


if [ $DJANGO_DEBUG == "on" ]; then
    ./manage.py runserver 0.0.0.0:8000
elif [ $DJANGO_MODE == "worker" ]; then
    ./manage.py runworker
else
    daphne -b 0.0.0.0 -p 8000 config.asgi:application
fi

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question