How do i run django-channels + nginx + gunicorn + redis in docker?

I am trying run an django asgi app with nginx + gunicorn + redis in docker.so far my wsgi application is running by gunicorn smoothly but somehow my django channels consumers are not connecting.

Docker-Compose

version: '3.9'

services:
  db:
   image: postgres
   volumes:
     - ./data/db:/var/lib/postgresql/data
   environment:
     - POSTGRES_DB=LiveSafer
     - POSTGRES_USER=postgres
     - POSTGRES_PASSWORD=demo1234
  ports:
    - "5432:5432"


  web:
   build: .
   command: >
    bash -c " python manage.py makemigrations &&
              python manage.py migrate &&
              gunicorn --bind 0.0.0.0:8000 LiveSafer.wsgi &&
              daphne -b 0.0.0.0 -p 8001 LiveSafer.routing:application
            "
   volumes:
    - .:/app
    - static_files:/app/static
   expose:
    - 8000
   ports:
    - 8001:8001
   links:
    - redis
   depends_on:
    - db


 nginx:
   build: ./nginx/
   ports: 
    - 80:80
   volumes:
    - ./nginx/conf.d/:/etc/nginx/conf.d/
    - static_files:/home/app/static
   depends_on:
    - web


 # database controller
 adminer:
   image: adminer:latest
   restart: always
   environment:
    - ADMINER_DEFAULT_SERVER=db
    - ADMINER_DESIGN=flat
    - ADMINER_PLUGINS=tables-filter
   ports:
    - 8080:8080


 redis:
  image: redis:latest
  command: ["redis-server", "--bind", "redis", "--port", "6379"]

volumes: static_files: db:

nginx

upstream django{
   server web:8000;
}

upstream channels-backend {
   server 127.0.0.1:8001;
}

server {
 listen 80;
 client_max_body_size 60M;

 location / {
    proxy_pass http://django;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header HOST $host;
 }

 location /ws/ {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_redirect off;
    proxy_pass http://127.0.0.1:8001;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Host $server_name;
 }

 location /media/ {
    alias /app/media/;
 }

 location /static/ {
    alias /home/app/static/;
 }

}

Terminal

lifvesafer-nginx-1    | 2022/12/20 07:00:56 [error] 31#31: *10 connect() failed (113: 
No route to host) while connecting to upstream, client: 172.19.0.1, server: , request: 
"GET /favicon.ico HTTP/1.1", upstream: "http://172.19.0.5:8000/favicon.ico", host: 
"127.0.0.1", referrer: "http://127.0.0.1/"

now i am not understanding why this is happening and how do i solve this

Back to Top