Django channels and docker-compose error

1.1k views Asked by At

When running runserver via docker and docker-compose, I get this error and I cannot connect to django:

django_1            | 2017-01-09 08:24:44,328 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.disconnect, websocket.receive
django_1            | 2017-01-09 08:24:44,329 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.disconnect, websocket.receive
django_1            | 2017-01-09 08:24:44,331 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.disconnect, websocket.receive
django_1            | 2017-01-09 08:24:44,331 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.disconnect, websocket.receive
django_1            | Unhandled exception in thread started by <function wrapper at 0x7ff06bee5d70>
django_1            | Traceback (most recent call last):
django_1            |   File "/usr/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
django_1            |     fn(*args, **kwargs)
django_1            |   File "/usr/local/lib/python2.7/site-packages/channels/management/commands/runserver.py", line 84, in inner_run
django_1            | Performing system checks...
django_1            | 
django_1            | System check identified no issues (0 silenced).
django_1            | January 09, 2017 - 08:24:44
django_1            | Django version 1.10.4, using settings 'backend.settings'
django_1            | Starting Channels development server at http://0.0.0.0:8000/
django_1            | Channel layer default (asgi_redis.core.RedisChannelLayer)
django_1            | Quit the server with CONTROL-C.
django_1            |     ws_protocols=getattr(settings, 'CHANNELS_WS_PROTOCOLS', None),
django_1            |   File "/usr/local/lib/python2.7/site-packages/daphne/server.py", line 41, in __init__
django_1            |     ''' % self.__class__.__name__)
django_1            | DeprecationWarning: 
django_1            |                 The host/port/unix_socket/file_descriptor keyword arguments to Server are deprecated.
django_1            |             

When running locally, everything is running ok. Here's my requirements.txt:

Django==1.10.4 psycopg2==2.6.2 channels==0.17.3 asgi-redis==1.0.0

And here's my docker-compose file:

version: '2' 
  services:
    redis:
      image: redis:3.0-alpine
    postgres:
        image: postgres
    django:
        build: ../backend
        command:  python backend/manage.py runserver 0.0.0.0:8000
        volumes:
            - ../backend:/backend
        ports:
            - "8000:8000"
        depends_on:
            - postgres
            - redis
            - django-migration
    django-migration:
        build: ../backend
        command: python backend/manage.py migrate
        volumes:
          - ../backend:/backend
        depends_on:
          - postgres
    client:
        image: node
        command: bash -c "cd src && npm start"
        ports:
            - "3000:3000"

Any ideas?

2

There are 2 answers

0
xtrinch On BEST ANSWER

Turns out I was using 1.0.0 version of daphne, meanwhile I was using an old version of django channels, and they are not compatible. Updating both fixed the error.

3
Bukharov Sergey On

Your containers don't has a link to each other. Try to unite them to network.

version: '2' 
  services:
    redis:
      image: redis:3.0-alpine
      networks:
       - django-network

    postgres:
        image: postgres
        networks:
         - django-network

    django:
        build: ../backend
        command:  python backend/manage.py runserver 0.0.0.0:8000
        volumes:
            - ../backend:/backend
        ports:
            - "8000:8000"
        depends_on:
            - postgres
            - redis
            - django-migration
        networks:
         - django-network

    django-migration:
        build: ../backend
        command: python backend/manage.py migrate
        volumes:
          - ../backend:/backend
        depends_on:
          - postgres
        networks:
         - django-network

    client:
        image: node
        command: bash -c "cd src && npm start"
        ports:
            - "3000:3000"
        networks:
         - django-network

     networks:
       tele-cluster-network:
         driver: bridge