Unable to connect to local redis docker although up and running

Viewed 587

Using the following redis.conf

▶ cat redis.conf                                                   
bind 0.0.0.0

spinning up a redis container

▶ docker run -d --name redis-test -p 11111:6379  -v /Users/redis.conf:/redis.conf redis redis-server /redis.conf
59eb1612e8c3e2403e18ce889ce1438f6c6a23a7c70bed30b46ff765b7fe7038

logs seem healthy

▶ docker logs -f 59eb1612e8c3e2403e18ce889ce1438f6c6a23a7c70bed30b46ff765b7fe7038                                                            
1:C 18 Mar 2021 17:57:13.954 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 18 Mar 2021 17:57:13.954 # Redis version=6.2.1, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 18 Mar 2021 17:57:13.954 # Configuration loaded
1:M 18 Mar 2021 17:57:13.955 * monotonic clock: POSIX clock_gettime
1:M 18 Mar 2021 17:57:13.955 * Running mode=standalone, port=6379.
1:M 18 Mar 2021 17:57:13.955 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 18 Mar 2021 17:57:13.956 # Server initialized
1:M 18 Mar 2021 17:57:13.956 * Ready to accept connections

container seems up

▶ docker ps | grep -i redis                
59eb1612e8c3   redis                  "docker-entrypoint.s…"   3 minutes ago        Up 3 minutes        0.0.0.0:11111->6379/tcp   redis-test

If all the above are more or less good indications, why am I unable to connect to the container

▶ redis-cli -h localhost -p 11111
Could not connect to Redis at localhost:11111: Connection refused
not connected> 
▶ redis-cli -h 127.0.0.1 -p 11111
Could not connect to Redis at 127.0.0.1:11111: Connection refused
not connected> 

Working on MacOS Catalina

1 Answers

Find the IP Address of container called redis-test by running this command (I'm in Linux, but I think that should be the same on MacOS, sorry if that's not the same):

docker inspect redis-test | grep -i ipaddress

The result should be something like this:

"IPAddress": "172.21.0.2"

Now try:

redis-cli -h 172.21.0.2 -p 11111
Related