[GH-ISSUE #703] If dockers containers are in the same host, couldn't be possible to use the container name and internal port? #593

Closed
opened 2026-02-26 06:33:33 +03:00 by kerem · 3 comments
Owner

Originally created by @joancifo on GitHub (Nov 7, 2020).
Original GitHub issue: https://github.com/NginxProxyManager/nginx-proxy-manager/issues/703

Checklist

What is troubling you?

If dockers containers are in the same host, couldn't be possible to use the container name and internal port?

For now, we have to EXPOSE the port and assign the IP in proxy host. But theoretically shouldn't be enough using the container name and "the internal port" without having to expose it ?

For example, if a container of the same host exposes the port 3333, the web can be accessible by the port 3333 and also by the proxy.

Thanks!

Originally created by @joancifo on GitHub (Nov 7, 2020). Original GitHub issue: https://github.com/NginxProxyManager/nginx-proxy-manager/issues/703 **Checklist** - Please read the [setup instructions](https://nginxproxymanager.com/setup/) - Please read the [FAQ](https://nginxproxymanager.com/faq/) **What is troubling you?** If dockers containers are in the same host, couldn't be possible to use the container name and internal port? For now, we have to EXPOSE the port and assign the IP in proxy host. But theoretically shouldn't be enough using the container name and "the internal port" without having to expose it ? For example, if a container of the same host exposes the port 3333, the web can be accessible by the port 3333 and also by the proxy. Thanks!
kerem 2026-02-26 06:33:33 +03:00
Author
Owner

@the-holger commented on GitHub (Nov 7, 2020):

If I understood you correctly then this is exactly what I am doing with (most of) my containers.
My setup is like this:

  • Nginx Proxy Manager is running in bridge mode, exposing all ports that I want to accept connections to (80, 443 for proxying, 81 for web admin), additionally it is in a network I called 'nginx-reverse-proxy'
  • All "client" machines are only in 'nginx-reverse-proxy' and don't expose any ports (except for very special cases I have not migrated yet)

You can only use the name resolution (i.e. using the container name) when both Nginx Proxy Manager and the proxied Container are in a network together (not both bridged). The Docker documentation helped me a lot here.

<!-- gh-comment-id:723484558 --> @the-holger commented on GitHub (Nov 7, 2020): If I understood you correctly then this is exactly what I am doing with (most of) my containers. My setup is like this: - Nginx Proxy Manager is running in bridge mode, exposing all ports that I want to accept connections to (80, 443 for proxying, 81 for web admin), additionally it is in a network I called 'nginx-reverse-proxy' - All "client" machines are only in 'nginx-reverse-proxy' and don't expose any ports (except for very special cases I have not migrated yet) You can only use the name resolution (i.e. using the container name) when both Nginx Proxy Manager and the proxied Container are in a network together (not both bridged). The [Docker documentation](https://docs.docker.com/network/network-tutorial-standalone/) helped me a lot here.
Author
Owner

@joancifo commented on GitHub (Nov 9, 2020):

Thanks for your reply.

Interesting, I didn't manage to connect via container name even they are in the same network (I use Portainer and both containers, NPM and a test container with a nginx, are in the bridge network).

Here I need to put the internal IP and the exposed port to connect to the containers (this works):
image

The container's name is "prova":
image

And the container configuration in Portainer:
image

However, using "prova" in NPM I get 502 Bad Gateway when I go to the URL.

<!-- gh-comment-id:723789417 --> @joancifo commented on GitHub (Nov 9, 2020): Thanks for your reply. Interesting, I didn't manage to connect via container name even they are in the same network (I use Portainer and both containers, NPM and a test container with a nginx, are in the bridge network). Here I need to put the internal IP and the exposed port to connect to the containers (this works): ![image](https://user-images.githubusercontent.com/567547/98506531-01f37480-225c-11eb-8180-7b5f3e61647e.png) The container's name is "prova": ![image](https://user-images.githubusercontent.com/567547/98506730-729a9100-225c-11eb-92e9-2e30c27fcc21.png) And the container configuration in Portainer: ![image](https://user-images.githubusercontent.com/567547/98506764-85ad6100-225c-11eb-8947-bf6dde3cb377.png) However, using "prova" in NPM I get 502 Bad Gateway when I go to the URL.
Author
Owner

@spcqike commented on GitHub (Dec 15, 2020):

are your container within the same docker-network?
each container can access all container that are in the same network. so if you have NPM with 172.17.0.1 and php with 172.17.0.2, nginx can access php via "php:80"

if you have isolated containers in stand alone networks (or stacks) with different IP ranges (npm as 172.17.0.1 and php as 172.18.0.1, ...) you must use the container IP (or, if you passtrough the container Ports to the host, you could also use the host ip and the port, like 192.168.0.32:8080)

i use several containers within one network and call them by name. so i need no "open" ports, except 80 and 443 (and 81). mysql, php, phpmyadmin, portainer, .... everything connects "local" in one docker network via container name. so in case of an container update/rebuild and therefore changed IP addresses, everything still works fine.

<!-- gh-comment-id:745146708 --> @spcqike commented on GitHub (Dec 15, 2020): are your container within the same docker-network? each container can access all container that are in the same network. so if you have NPM with 172.17.0.1 and php with 172.17.0.2, nginx can access php via "php:80" if you have isolated containers in stand alone networks (or stacks) with different IP ranges (npm as 172.17.0.1 and php as 172.18.0.1, ...) you must use the container IP (or, if you passtrough the container Ports to the host, you could also use the host ip and the port, like 192.168.0.32:8080) i use several containers within one network and call them by name. so i need no "open" ports, except 80 and 443 (and 81). mysql, php, phpmyadmin, portainer, .... everything connects "local" in one docker network via container name. so in case of an container update/rebuild and therefore changed IP addresses, everything still works fine.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/nginx-proxy-manager-NginxProxyManager#593
No description provided.