Search code examples
google-cloud-runcloud-run-emulator

Access to localhost from a locally deployed Cloud Run container (through VS Code)


I am running a Cloud Run service on the Cloud Run emulator through VS Code. At some point, I need to access to data stored on a Firebase Storage local emulator (say localhost:9199). However, my Python code on Cloud Run is facing this issue:

<urllib3.connection.HTTPConnection object at 0x7f6d392af2e0>: Failed to establish a new connection: [Errno 111] Connection refused

Some investigations led me thinking that because Cloud Run emulator is running a virtual machine, it does not know about localhost:9199.

Referring to this answer here, is it possible to add -net host option to the docker internally used by Cloud Run? If not, any idea to solve this will be highly appreciated.


Solution

  • Ok, it turned out to be simpler than I thought, but if it can save to someone a few hours, here is how I solved the issue:

    I simply replaced localhost with host.docker.internal in the code running from within the docker container, and that was it. Credits go to this answer, where you will find more details based on your system config.