我正在对接一个使用django频道实现websocket功能的web应用程序。这取决于redis。我无法让应用程序的redis部分正常工作。我试着坚持这个redis/compose指南。 docker-compose.yml
```
version: "3"
services:
db:
image: mysql:latest
volumes:
- "./.mysql-data/db:/var/lib/mysql"
restart: always
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: database
MYSQL_USER: user
MYSQL_PASSWORD: password
networks:
- hostnetwork
backend:
build: ./backend
command: daphne -b 0.0.0.0 -p 8000 main.asgi:application
volumes:
- ./backend:/code
ports:
- "8000:8000"
depends_on:
- db
links:
- redis
redis:
image: "redis:alpine"
command: redis-server
ports:
- "6379:6379"
volumes:
- ./redis-data:/var/lib/redis <-- This dir doesn't exist on host machine
- ./redis.conf:/usr/local/etc/redis/redis.conf <-- I created this file manually on host machine
environment:
- REDIS_REPLICATION_MODE=master
networks:
node_net:
ipv4_address: 172.28.1.4
frontend:
build: ./frontend
ports:
- "3000:3000"
volumes:
- ./frontend:/usr/src/app
stdin_open: true
networks:
hostnetwork:
external: true
node_net:
ipam:
driver: default
config:
- subnet: 172.28.0.0/16`settings.py`
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [
(os.environ.get('REDIS_HOST', "172.28.1.4"),
os.environ.get('REDIS_PORT', 6379))
],
},
},
}
通过上面的配置,我的容器启动了,redis一开始不会给出任何错误,但是websocket消费者永远不会收到或发送任何消息。大约一分钟后,会出现以下错误:
backend_1 | File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 494, in sock_connect
backend_1 | return await fut
backend_1 | File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 526, in _sock_connect_cb
backend_1 | raise OSError(err, f'Connect call failed {address}')
backend_1 | TimeoutError: [Errno 110] Connect call failed ('172.28.1.4', 6379)
是什么导致了 `TimeoutError` 我的服务器和redis之间明显缺乏通信?我怎样才能让两个说话?
1条答案
按热度按时间ftf50wuq1#
这个答案让我明白了我需要解决我的问题。我只是删除了:
改变了
CHANNEL_LAYERS
对此:我想这使得我的服务可以通过
docker-compose
创造。