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.
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
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.
Try below command
src/redis-cli -h localhost -p 6379
-p 6379
–
Varityper 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
© 2022 - 2024 — McMap. All rights reserved.
redis-cli
is finally able to connect. I also noticed, that during when it cannot connect, I have to typeexit
command twice just to close the shell. I am usingredis-cli 4.0.6
and my redis server running in docker is4.0.2
. Also, I am in Ubuntu. – Philpot