Nginx proxy + my HTTP service in Google Cloud Run

I’m setting up two containers in a Google Cloud Run service (which run on same host):

  • ingress nginx proxy
  • my http service

I got these running locally on Mac, but when deploying to Google Cloud Run, I’ve hit:

nginx [emerg] host not found in upstream host.docker.internal

because I’m using host.docker.internal in nginx configuration, and host.docker.internal isn’t defined (on Linux) as I found out (nginx - From inside of a Docker container, how do I connect to the localhost of the machine? - Stack Overflow)

First of all this sucks – why does this work on Mac, but not on Linux … seems like host.docker.internal should be always available!? (Explore networking features on Docker Desktop | Docker Docs)

There seem to be few workarounds for this sucky thing:

  • pass --add-host="host.docker.internal:172.17.0.1" to the docker run command
  • pass --network=host and use ‘localhost’
  • using docker-compose.yml and actually building an image with /etc/hosts containing the mapping.

Cloud Run service config provides two text fields – “Container Command” and “Container Arguments” – but I can’t figure out how to actually use them, it’s like some alien technology - and I can’t find good documentation or examples.

What am I missing here? I thought this would take me 30 min to 3 hours to set up an Nginx proxy, but it’s already close to 3 days. Please help.

And I just came across this article, which talks exactly about my scenario, and basically, referring to 127.0.0.1 in nginx config works in Google Cloud Run (not in the local desktop docker when I tried it earlier)…

Cloud Run appears to create a Kubernetes Pod. Containers in a Pod share the same network namespace, and that’s why localhost is the same localhost for all containers inside the same pod.

The special DNS name host.docker.internal is a feature of Docker Desktop only. Though Docker-CE can use host.docker.internal and gateway.docker.internal to access the host by its ip as well. My bad, those names only worked with Docker-CE, because I have Docker Desktop on the host. I confused it with --add-host host.docker.internal=host-gateway, which is equivalent to --add-host host.docker.internal=172.17.0.1

1 Like