nginx inside docker: mapping localhost:port in one container to another_container:port

Sim Tov smntov at
Wed May 29 11:53:57 UTC 2019

I have a custom network and two containers A and B connected to it.
Container A (with Debian inside) runs nginx and an application that listens
to localhost:8083 and expects certain service there. Once deployed this
service runs in container B and not locally. For certain reasons I can't
change localhost to something else inside the application.


   How can I map localhost:8083 from A to name_of_container_B:8083 on the
   Docker/nginx/infrastructure/OS level? name_of_container_B is not known
   during creation of A image, but I can pass it as docker entrypoint
   parameter during launch of conatiner A.

   I prefer not to add additional packages in order not to increase overall
   complexity. So is it, for example, possible to configure nginx somehow to
   listen on localhost:8083 and forward it to name_of_container_B:8083?

   I actually use Ansible to start containers, so the solution needs to be
   applicable using Ansible?

Thank you!
Link to this question:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list