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



enter image description here










share|improve this question
























  • 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















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



enter image description here










share|improve this question
























  • 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













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



enter image description here










share|improve this question















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



enter image description here







django redis






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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












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





share|improve this answer























  • in python what changes i need to do.
    – soubhagya
    2 days ago






  • 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










  • 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













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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

























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





share|improve this answer























  • in python what changes i need to do.
    – soubhagya
    2 days ago






  • 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










  • 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

















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





share|improve this answer























  • in python what changes i need to do.
    – soubhagya
    2 days ago






  • 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










  • 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















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





share|improve this answer














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






share|improve this answer














share|improve this answer



share|improve this answer








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 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






  • 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






  • 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










  • 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




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

ts Property 'filter' does not exist on type '{}'

mat-slide-toggle shouldn't change it's state when I click cancel in confirmation window