У меня есть приложение django
, которое использует channels
, channels_redis
и graphene_subscriptions
. graphene_subscriptions
используется для публикации sh сообщения через channels
при сохранении экземпляра модели базы данных (DATABASE_MODEL_INSTANCE.save()
).
Приложение Django и redis
(а также другие часть приложения fullstack, конечно) запускается отдельными docker контейнерами, используя docker-compose
. Когда я запускаю установку с docker-compose
в сетевом режиме хоста на Linux все просто отлично. Однако, если переконфигурировать настройки для моста в сетевом режиме с пользовательскими сетями (один для бэкэнда, другой для внешнего интерфейса) и запустить установку с docker-compose
, я получаю следующую ошибку:
c_backend | File "./APP_SPECIFIC_PATH/FILE.py", line X, in FUNCTION
c_backend | DATABASE_MODEL_INSTANCE.save()
c_backend | File "/usr/local/lib/python3.7/site-packages/django/db/models/base.py", line 746, in save
c_backend | force_update=force_update, update_fields=update_fields)
c_backend | File "/usr/local/lib/python3.7/site-packages/django/db/models/base.py", line 795, in save_base
c_backend | update_fields=update_fields, raw=raw, using=using,
c_backend | File "/usr/local/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 175, in send
c_backend | for receiver in self._live_receivers(sender)
c_backend | File "/usr/local/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 175, in <listcomp>
c_backend | for receiver in self._live_receivers(sender)
c_backend | File "/usr/local/lib/python3.7/site-packages/graphene_subscriptions/signals.py", line 15, in post_save_subscription
c_backend | event.send()
c_backend | File "/usr/local/lib/python3.7/site-packages/graphene_subscriptions/events.py", line 20, in send
c_backend | "subscriptions", {"type": "signal.fired", "event": self.to_dict()}
c_backend | File "/usr/local/lib/python3.7/site-packages/asgiref/sync.py", line 116, in __call__
c_backend | return call_result.result()
c_backend | File "/usr/local/lib/python3.7/concurrent/futures/_base.py", line 428, in result
c_backend | return self.__get_result()
c_backend | File "/usr/local/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
c_backend | raise self._exception
c_backend | File "/usr/local/lib/python3.7/site-packages/asgiref/sync.py", line 156, in main_wrap
c_backend | result = await self.awaitable(*args, **kwargs)
c_backend | File "/usr/local/lib/python3.7/site-packages/channels_redis/core.py", line 614, in group_send
c_backend | async with self.connection(self.consistent_hash(group)) as connection:
c_backend | File "/usr/local/lib/python3.7/site-packages/channels_redis/core.py", line 835, in __aenter__
c_backend | self.conn = await self.pool.pop()
c_backend | File "/usr/local/lib/python3.7/site-packages/channels_redis/core.py", line 73, in pop
c_backend | conns.append(await aioredis.create_redis(**self.host, loop=loop))
c_backend | File "/usr/local/lib/python3.7/site-packages/aioredis/commands/__init__.py", line 175, in create_redis
c_backend | loop=loop)
c_backend | File "/usr/local/lib/python3.7/site-packages/aioredis/connection.py", line 113, in create_connection
c_backend | timeout)
c_backend | File "/usr/local/lib/python3.7/asyncio/tasks.py", line 414, in wait_for
c_backend | return await fut
c_backend | File "/usr/local/lib/python3.7/site-packages/aioredis/stream.py", line 24, in open_connection
c_backend | lambda: protocol, host, port, **kwds)
c_backend | File "/usr/local/lib/python3.7/asyncio/base_events.py", line 909, in create_connection
c_backend | type=socket.SOCK_STREAM, proto=proto, flags=flags, loop=self)
c_backend | File "/usr/local/lib/python3.7/asyncio/base_events.py", line 1286, in _ensure_resolved
c_backend | proto=proto, flags=flags)
c_backend | File "/usr/local/lib/python3.7/asyncio/base_events.py", line 788, in getaddrinfo
c_backend | None, getaddr_func, host, port, family, type, proto, flags)
c_backend | File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
c_backend | result = self.fn(*self.args, **self.kwargs)
c_backend | File "/usr/local/lib/python3.7/socket.py", line 752, in getaddrinfo
c_backend | for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
c_backend | socket.gaierror: [Errno -2] Name or service not known
Моя конфигурация разработки выглядит как показано ниже.
Выдержка из settings.py
файла:
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [("redis", 6379)],
},
},
}
Выдержка из redis.conf
файла:
#bind 127.0.0.1
protected-mode no
Выдержка из nginx.conf
файла:
upstream django {
server django:8080;
}
server {
listen 8000;
listen [::]:8000;
location /graphql/subscriptions {
proxy_pass http://django/graphql/subscriptions;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
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;
}
}
Выдержка из docker-compose.yml
файла:
version: "3.5"
services:
redis:
image: redis:5.0.7-alpine
hostname: redis
container_name: c_redis
networks:
- nw_backend
ports:
- "6379:6379"
volumes:
- ./redis/redis.conf:/usr/local/etc/redis/redis.conf:ro
command: [ "redis-server", "/usr/local/etc/redis/redis.conf" ]
nginx:
image: nginx:1.17.9-alpine
hostname: nginx
container_name: c_nginx
networks:
- nw_frontend
- nw_backend
expose:
- "80"
- "8000"
ports:
- "80:8000"
- "8000:8000"
volumes:
- ./nginx/nginx.conf:/etc/nginx/conf.d/nginx.conf:ro
depends_on:
- django
django:
hostname: django
container_name: c_django
ports:
- "8080:8080"
depends_on:
- redis
- database
networks:
- nw_frontend
- nw_backend
networks:
nw_frontend:
driver: bridge
name: n_frontend
nw_backend:
driver: bridge
name: n_backend
Что я пропустил во время настройки?