通过 docker 和 docker-compose 运行 runserver 时,出现此错误并且无法连接到 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 |
在本地运行时,一切运行正常。这是我的requirements.txt:
Django==1.10.4 psycopg2==2.6.2 频道==0.17.3 asgi-redis==1.0.0
这是我的 docker-compose 文件:
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"
有任何想法吗?