2

I'm making local cloud run services with the Cloud Code plugin to Intellij (PyCharm) but the locally deployed service cannot connect to the redis instance running in Docker:

redis.exceptions.ConnectionError: Error 111 connecting to 127.0.0.1:6379. Connection refused.

I can connect to the locally running redis instance from a python shell, it's just the cloud run service running in minikube/docker that cannot seem to connect to it.

Any ideas?

Edit since people are suggesting completely unrelated posts - The locally running Cloud Run instance makes use of Docker and Minikube to run, and is automatically configured by Cloud Code for Intellij. I suspect that Cloud Code for intellij puts Cloud Run instances into an environment that cannot access services running on MacOS localhost (but can access the Internet), which is why I tagged those specific items in the post. Please limit suggestions to ones that takes these items into account.

Donnald Cucharo
  • 3,866
  • 1
  • 10
  • 17
Michael
  • 1,428
  • 3
  • 15
  • 34
  • Please show information on how you're connecting to your Redis instance. Also, what's on your Dockerfile and your dependencies? There's a very similar thread to your post and this could help https://stackoverflow.com/questions/36088409/error-111-connecting-to-localhost6379-connection-refused-django-heroku – Donnald Cucharo Feb 19 '21 at 06:15
  • Thanks but that's not similar at all. The locally running cloud run instance makes use of docker and minikube to run, and is automatically configured by Cloud Code for Intellij. I suspect that Cloud Code for intellij puts Cloud Run instances into an environment that cannot access services running on MacOS localhost, which is why I tagged those specific items in the post. – Michael Feb 19 '21 at 08:49

1 Answers1

4

If you check Docker network using:

docker network list

You'll see a network called cloud-run-dev-internal. You need to connect your Redis container to that network. To do that, run this command (This instruction assumes that your container name is some-redis):

docker network connect cloud-run-dev-internal some-redis

Double check that your container is connected to the network:

docker network inspect cloud-run-dev-internal

Then connect to Redis Host using the container name:

import redis
...

redis_host = os.environ.get('REDISHOST', 'some-redis')
redis_port = int(os.environ.get('REDISPORT', 6379))
redis_client = redis.StrictRedis(host=redis_host, port=redis_port)
Donnald Cucharo
  • 3,866
  • 1
  • 10
  • 17
  • Thank you this is exactly what I needed. The docker network inspect command was especially useful since the bridge uses local network address space (not 127.0.0.1). – Michael Feb 19 '21 at 12:29