With nginx and mongodb running in docker, how to reverse proxy to mongodb?

Solution for With nginx and mongodb running in docker, how to reverse proxy to mongodb?
is Given Below:

My docker-compose.yml has our team’s app stack of several modules, plus MongoDB and NGINX as the ingress point, all as Docker images. I have NGINX working well to reverse proxy to our UI module, and everything can communicate as needed with each other on the docker network. I have followed various tutorials to use the stream module, like:

stream {
  server {
    listen 27020;
    proxy_connect_timeout 1s;
    proxy_timeout 3s;
    proxy_pass mongodb;
  }
  upstream mongodb {
    server mongodb:27017;
  }
}

In docker-compose.yml, the mongodb service is named “mongodb”, and all of the services can contact it this way. But when I attempt to connect to mongodb, I do not even see an attempt in the NGINX docker log. Tomorrow, I will have to see if there are any firewall rules that might be blocking the port from clients, but is there any reason why this should not work for me, at least to the point where I can see the connection attempt in the NGINX docker log? NGINX starts up fine, without complaining that it doesn’t know about the “stream” directive, so that indicates that our NGINX image is compiled with the stream module. Other than all of that, I am drawing a blank.