django-redis connection error inside docker
up vote
1
down vote
favorite
django views.py
import redis
import jwt
from access import utils
import os
redis_url = os.environ['REDIS_URI']
R = redis.StrictRedis(redis_url)
def set(request):
R.set('foo', 'bar')
return JsonResponse({"code":200,"msg":"success"})
docker-compose
version: "3"
services:
rango:
container_name: rango
build: ./
command: python backend/manage.py runserver 0.0.0.0:8000
# command: npm start --prefix frontend/rango-frontend/
working_dir: /usr/src/rango
environment:
REDIS_URI: redis://redis_db:6379
ports:
- "8000:8000"
tty: true
links:
- elasticsearch
- node
- redis
#elastic search
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.5.0
ports:
- "9200:9200"
#node
node:
image: node:10.13.0
#redis
redis:
image: redis
environment:
- ALLOW_EMPTY_PASSWORD=yes
ports:
- "6379:6379"
here i am connecting redis from django inside docker.
it is giving me exceptions connexctions refused.
Please have a look into my code and shared screenshot below
django redis
add a comment |
up vote
1
down vote
favorite
django views.py
import redis
import jwt
from access import utils
import os
redis_url = os.environ['REDIS_URI']
R = redis.StrictRedis(redis_url)
def set(request):
R.set('foo', 'bar')
return JsonResponse({"code":200,"msg":"success"})
docker-compose
version: "3"
services:
rango:
container_name: rango
build: ./
command: python backend/manage.py runserver 0.0.0.0:8000
# command: npm start --prefix frontend/rango-frontend/
working_dir: /usr/src/rango
environment:
REDIS_URI: redis://redis_db:6379
ports:
- "8000:8000"
tty: true
links:
- elasticsearch
- node
- redis
#elastic search
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.5.0
ports:
- "9200:9200"
#node
node:
image: node:10.13.0
#redis
redis:
image: redis
environment:
- ALLOW_EMPTY_PASSWORD=yes
ports:
- "6379:6379"
here i am connecting redis from django inside docker.
it is giving me exceptions connexctions refused.
Please have a look into my code and shared screenshot below
django redis
Welcome to Stack Overflow. In addition to posting the code, please be sure to ask a clear question. How to Ask. Thanks.
– Elletlar
Nov 18 at 10:00
Could you show your Redis configuration in settings.py?
– Kamil
2 days ago
i am not using redis with client. not in settinggs.py
– soubhagya
2 days ago
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
django views.py
import redis
import jwt
from access import utils
import os
redis_url = os.environ['REDIS_URI']
R = redis.StrictRedis(redis_url)
def set(request):
R.set('foo', 'bar')
return JsonResponse({"code":200,"msg":"success"})
docker-compose
version: "3"
services:
rango:
container_name: rango
build: ./
command: python backend/manage.py runserver 0.0.0.0:8000
# command: npm start --prefix frontend/rango-frontend/
working_dir: /usr/src/rango
environment:
REDIS_URI: redis://redis_db:6379
ports:
- "8000:8000"
tty: true
links:
- elasticsearch
- node
- redis
#elastic search
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.5.0
ports:
- "9200:9200"
#node
node:
image: node:10.13.0
#redis
redis:
image: redis
environment:
- ALLOW_EMPTY_PASSWORD=yes
ports:
- "6379:6379"
here i am connecting redis from django inside docker.
it is giving me exceptions connexctions refused.
Please have a look into my code and shared screenshot below
django redis
django views.py
import redis
import jwt
from access import utils
import os
redis_url = os.environ['REDIS_URI']
R = redis.StrictRedis(redis_url)
def set(request):
R.set('foo', 'bar')
return JsonResponse({"code":200,"msg":"success"})
docker-compose
version: "3"
services:
rango:
container_name: rango
build: ./
command: python backend/manage.py runserver 0.0.0.0:8000
# command: npm start --prefix frontend/rango-frontend/
working_dir: /usr/src/rango
environment:
REDIS_URI: redis://redis_db:6379
ports:
- "8000:8000"
tty: true
links:
- elasticsearch
- node
- redis
#elastic search
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.5.0
ports:
- "9200:9200"
#node
node:
image: node:10.13.0
#redis
redis:
image: redis
environment:
- ALLOW_EMPTY_PASSWORD=yes
ports:
- "6379:6379"
here i am connecting redis from django inside docker.
it is giving me exceptions connexctions refused.
Please have a look into my code and shared screenshot below
django redis
django redis
edited Nov 18 at 10:01
asked Nov 18 at 9:54
soubhagya
356
356
Welcome to Stack Overflow. In addition to posting the code, please be sure to ask a clear question. How to Ask. Thanks.
– Elletlar
Nov 18 at 10:00
Could you show your Redis configuration in settings.py?
– Kamil
2 days ago
i am not using redis with client. not in settinggs.py
– soubhagya
2 days ago
add a comment |
Welcome to Stack Overflow. In addition to posting the code, please be sure to ask a clear question. How to Ask. Thanks.
– Elletlar
Nov 18 at 10:00
Could you show your Redis configuration in settings.py?
– Kamil
2 days ago
i am not using redis with client. not in settinggs.py
– soubhagya
2 days ago
Welcome to Stack Overflow. In addition to posting the code, please be sure to ask a clear question. How to Ask. Thanks.
– Elletlar
Nov 18 at 10:00
Welcome to Stack Overflow. In addition to posting the code, please be sure to ask a clear question. How to Ask. Thanks.
– Elletlar
Nov 18 at 10:00
Could you show your Redis configuration in settings.py?
– Kamil
2 days ago
Could you show your Redis configuration in settings.py?
– Kamil
2 days ago
i am not using redis with client. not in settinggs.py
– soubhagya
2 days ago
i am not using redis with client. not in settinggs.py
– soubhagya
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
By default, docker compose makes containers discoverable with a hostname identical to the container name. Your redis container is thus discoverable via the hostname redis
. However, your Django container is using the hostname redis_db
.
Update your docker-compose.yml
and change the REDIS_URI
to reference the correct hostname:
REDIS_URI: redis://redis:6379
in python what changes i need to do.
– soubhagya
2 days ago
1
No changes in python. You just need to update yourdocker-compose.yml
and change theREDIS_URI
toredis://redis:6379
– Will Keeling
2 days ago
and do i nee to start redis inside the docker or it will automatically start. just like in local system we need to start redis server before working on it using src/redis-server
– soubhagya
2 days ago
1
Redis will come up when the container starts. You don't need to enter the container to start it.
– Will Keeling
yesterday
okk. thanksi will try as per your suggestion
– soubhagya
yesterday
|
show 5 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
By default, docker compose makes containers discoverable with a hostname identical to the container name. Your redis container is thus discoverable via the hostname redis
. However, your Django container is using the hostname redis_db
.
Update your docker-compose.yml
and change the REDIS_URI
to reference the correct hostname:
REDIS_URI: redis://redis:6379
in python what changes i need to do.
– soubhagya
2 days ago
1
No changes in python. You just need to update yourdocker-compose.yml
and change theREDIS_URI
toredis://redis:6379
– Will Keeling
2 days ago
and do i nee to start redis inside the docker or it will automatically start. just like in local system we need to start redis server before working on it using src/redis-server
– soubhagya
2 days ago
1
Redis will come up when the container starts. You don't need to enter the container to start it.
– Will Keeling
yesterday
okk. thanksi will try as per your suggestion
– soubhagya
yesterday
|
show 5 more comments
up vote
1
down vote
accepted
By default, docker compose makes containers discoverable with a hostname identical to the container name. Your redis container is thus discoverable via the hostname redis
. However, your Django container is using the hostname redis_db
.
Update your docker-compose.yml
and change the REDIS_URI
to reference the correct hostname:
REDIS_URI: redis://redis:6379
in python what changes i need to do.
– soubhagya
2 days ago
1
No changes in python. You just need to update yourdocker-compose.yml
and change theREDIS_URI
toredis://redis:6379
– Will Keeling
2 days ago
and do i nee to start redis inside the docker or it will automatically start. just like in local system we need to start redis server before working on it using src/redis-server
– soubhagya
2 days ago
1
Redis will come up when the container starts. You don't need to enter the container to start it.
– Will Keeling
yesterday
okk. thanksi will try as per your suggestion
– soubhagya
yesterday
|
show 5 more comments
up vote
1
down vote
accepted
up vote
1
down vote
accepted
By default, docker compose makes containers discoverable with a hostname identical to the container name. Your redis container is thus discoverable via the hostname redis
. However, your Django container is using the hostname redis_db
.
Update your docker-compose.yml
and change the REDIS_URI
to reference the correct hostname:
REDIS_URI: redis://redis:6379
By default, docker compose makes containers discoverable with a hostname identical to the container name. Your redis container is thus discoverable via the hostname redis
. However, your Django container is using the hostname redis_db
.
Update your docker-compose.yml
and change the REDIS_URI
to reference the correct hostname:
REDIS_URI: redis://redis:6379
edited yesterday
answered 2 days ago
Will Keeling
9,88122329
9,88122329
in python what changes i need to do.
– soubhagya
2 days ago
1
No changes in python. You just need to update yourdocker-compose.yml
and change theREDIS_URI
toredis://redis:6379
– Will Keeling
2 days ago
and do i nee to start redis inside the docker or it will automatically start. just like in local system we need to start redis server before working on it using src/redis-server
– soubhagya
2 days ago
1
Redis will come up when the container starts. You don't need to enter the container to start it.
– Will Keeling
yesterday
okk. thanksi will try as per your suggestion
– soubhagya
yesterday
|
show 5 more comments
in python what changes i need to do.
– soubhagya
2 days ago
1
No changes in python. You just need to update yourdocker-compose.yml
and change theREDIS_URI
toredis://redis:6379
– Will Keeling
2 days ago
and do i nee to start redis inside the docker or it will automatically start. just like in local system we need to start redis server before working on it using src/redis-server
– soubhagya
2 days ago
1
Redis will come up when the container starts. You don't need to enter the container to start it.
– Will Keeling
yesterday
okk. thanksi will try as per your suggestion
– soubhagya
yesterday
in python what changes i need to do.
– soubhagya
2 days ago
in python what changes i need to do.
– soubhagya
2 days ago
1
1
No changes in python. You just need to update your
docker-compose.yml
and change the REDIS_URI
to redis://redis:6379
– Will Keeling
2 days ago
No changes in python. You just need to update your
docker-compose.yml
and change the REDIS_URI
to redis://redis:6379
– Will Keeling
2 days ago
and do i nee to start redis inside the docker or it will automatically start. just like in local system we need to start redis server before working on it using src/redis-server
– soubhagya
2 days ago
and do i nee to start redis inside the docker or it will automatically start. just like in local system we need to start redis server before working on it using src/redis-server
– soubhagya
2 days ago
1
1
Redis will come up when the container starts. You don't need to enter the container to start it.
– Will Keeling
yesterday
Redis will come up when the container starts. You don't need to enter the container to start it.
– Will Keeling
yesterday
okk. thanksi will try as per your suggestion
– soubhagya
yesterday
okk. thanksi will try as per your suggestion
– soubhagya
yesterday
|
show 5 more comments
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53359634%2fdjango-redis-connection-error-inside-docker%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Welcome to Stack Overflow. In addition to posting the code, please be sure to ask a clear question. How to Ask. Thanks.
– Elletlar
Nov 18 at 10:00
Could you show your Redis configuration in settings.py?
– Kamil
2 days ago
i am not using redis with client. not in settinggs.py
– soubhagya
2 days ago