I'm trying to deploy django channels with Docker and Django doesn't seem to find Redis (which I'm using as a channel layer).
When I do it locally, I just run redis-server
and point to it from settings:
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
'hosts': [('localhost', 6379)],
},
},
}
Everything works fine, web sockets are accepting connections and easily transfer my data. For production environment I use this docker config:
version: "3"
services:
backend:
container_name: backend
restart: 'on-failure'
image: registry.testtesttest.com/app/backend:${BACKEND_VERSION:-latest}
ports:
- "8000:8000"
environment:
DJANGO_SETTINGS_MODULE: ${DJANGO_SETTINGS_MODULE:-settings.production}
DJANGO_SECRET_KEY: ${DJANGO_SECRET_KEY:-dev}
redis:
image: "redis:alpine"
ports:
-"6379:6379"
And I point to redis from production settings:
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
'hosts': [('redis', 6379)],
},
},
}
And on production, Django says:
Cannot find redis on 127.0.0.1:6379
What am I doing wrong? Do I have to add any extra services do docker-compose file?
You need to give links for backend.
backend:
container_name: backend
restart: 'on-failure'
image: registry.testtesttest.com/app/backend:${BACKEND_VERSION:-latest}
ports:
- "8000:8000"
environment:
DJANGO_SETTINGS_MODULE: ${DJANGO_SETTINGS_MODULE:-settings.production}
DJANGO_SECRET_KEY: ${DJANGO_SECRET_KEY:-dev}
links:
- redis
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With