supergentle
supergentle

Reputation: 1091

Connecting to Redis server from an app sitting in a docker

EDIT

For those who have the same issue with me, check the question/solution here: How to access host port from docker container

TL;DR If you are a MAC user, use "docker.for.mac.localhost" instead of "localhost" or "127.0.0.1"


So I have an application running in a docker container. The thing is now I want to set up Redis server "OUTSIDE" of the docker and make the app in the docker utilize the server.

I installed the Redis server, and it's working good. the hostname is 127.0.0.1, and the port number is 6379. I set that up in the app's config.

However, the app returns an error message that the connection has been refused from 127.0.0.1:6379.

I think the app is aware that the Redis server is out there, but for some reasons (I guess permission issue?) the connection attempt has been declined from the Redis server.

Please share me with me anything that could solve this issue. Thanks!

Upvotes: 4

Views: 2520

Answers (1)

Shen Yudong
Shen Yudong

Reputation: 1230

in docker container, the ip 127.0.0.1 only can connect to server inside of container. you have to connect to host's redis server with a host's ip address. And run this command in host: netstat -apn | grep 6379, check which ip your redis server is listening on. if it's 127.0.0.1 , you only can connect to it from host, can't connect from a container.

Upvotes: 1

Related Questions