Error :Could not connect to Redis at redis:6379: Name or service not known
Asked Answered
S

4

19

I am trying to execute the container named redis which is running right now.But the error Could not connect to Redis at redis:6379: Name or service not known. Any one please hell me to figure out the issue and fix it.

Stand answered 15/10, 2015 at 7:14 Comment(2)
You're going to need to give us a lot more details. How did you run the container and how did you try to connect to it?Rhyne
it is very weird, that i encounter this very same problem. I keep typing same command and open different shells...Until, after a while... redis-cli is finally able to connect. I also noticed, that during when it cannot connect, I have to type exit command twice just to close the shell. I am using redis-cli 4.0.6 and my redis server running in docker is 4.0.2. Also, I am in Ubuntu.Philpot
U
8

This is because both the containers are not in same network, Add a network property inside service name and make sure its same for both

    redis:
      networks:
        - redis-net
Underclay answered 3/7, 2019 at 9:19 Comment(1)
God bless you. I have been searching fo hours what was the reason and adding the network solved the issue. ThanksCopulation
G
7

Naming the container doesn't alter your hosts file or DNS, and depending on how you ran the container it may not be accessible via the standard port as Docker does port translation.

Run docker inspect redis and examine the ports output, it will tell you what port it is accessible on as well as the IP. Note, however, that this will only be connectable over that IP from that host. To access it from off of the host you will need to use the port from the above command and the host's IP address. That assumes your local firewall rules allow it, which are beyond the scope of this site.

Gilman answered 16/10, 2015 at 2:6 Comment(0)
E
5

Try below command

src/redis-cli -h localhost -p 6379
Episcopalism answered 22/7, 2019 at 14:11 Comment(1)
thanks.. yes separating the port is working -p 6379Varityper
C
2

You can try the following network setup steps if you are following the official docker tutorial

docker network create some-network

After that you can add the next command to connect to the network, this solved my issue:

docker network connect some-network some-redis

And finally, run the Redis server locally.

​​docker run -it --network some-network --rm redis redis-cli -h some-redis
Centra answered 28/5 at 14:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.