Configuring Daphne for Django Channels
In Chapter 16, Building a Chat Server, you used Django Channels to build a chat server using WebSockets and you used Daphne to serve asynchronous requests by replacing the standard Django runserver
command. We will add Daphne to our production environment.
Let’s create a new service in the Docker Compose file to run the Daphne web server.
Edit the docker-compose.yml
file and add the following lines inside the services
block:
daphne:
build: .
working_dir: /code/educa/
command: ["../wait-for-it.sh", "db:5432", "--",
"daphne", "-b", "0.0.0.0", "-p", "9001",
"educa.asgi:application"]
restart: always
volumes:
- .:/code
environment:
- DJANGO_SETTINGS_MODULE=educa.settings.prod
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
depends_on...