docker-compose.yal文件中:redis:image:rediscontainer_name:xdemo.redisports:-6379:6379restart:alwaysdjangosetting.py
docker-compose.yal文件中:
redis:
image: redis
container_name: xdemo.redis
ports:
- 6379:6379
restart: always
django setting.py中配置redis:
CACHES = {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': 'redis://127.0.0.1:6379',
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"PASSWORD": "",
},
},
}
访问redis的时候总是报错:
redis.exceptions.ConnectionError: Error 111 connecting to 127.0.0.1:6379. Connection refused.
解决方法:将127.0.0.1设置为,docker中配置的servername, redis:
CACHES = {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': 'redis://redis:6379',
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"PASSWORD": "",
},
},
}
以上这篇docker django无法访问redis容器的解决方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
docker django redis