Docker Networking - Container Name and different Port


Recommended Posts

On 8/6/2022 at 6:18 AM, Stephan M. said:

Hi,

I'm trying to use Docker Container name to map to different Container settings. My problem is that I need to give the setting a different port.
Same like with IP: 192.168.178.100:1234
Just with name: container-name:1234 (that is unfortunately not working)

I am not certain i understand the question. It sounds like you are trying to allow one container to talk to another using the container name as a hostname. If so you will need to have both containers on the same custom bridge network, the default bridge network will not work as it does not support using container names as internal hostnames. If they are on the same custom bridge network then the specifying container-name:port in the setting of one containers application should allow you to reach another (no need to make a port mapping in this case either so long as the port is only for internal communication). 

Link to comment
13 hours ago, primeval_god said:

It sounds like you are trying to allow one container to talk to another using the container name as a hostname.

Yes

13 hours ago, primeval_god said:

so you will need to have both containers on the same custom bridge network

It is in the same docker custom network that is in bridge mode

13 hours ago, primeval_god said:

then the specifying container-name:port in the setting of one containers application should allow you to reach another

With just that the application is doing something like container_name:my_port:default_port_of_application

13 hours ago, primeval_god said:

no need to make a port mapping in this case either so long as the port is only for internal communication

how can I do that?

 

Thank you very much.

Link to comment
6 hours ago, Stephan M. said:

With just that the application is doing something like container_name:my_port:default_port_of_application

I think i may see the issue. Rather than specifying container-name:my_port just specify container-name to the application, it looks like it will add the default port number on its own.

When working with containers that communicate on an internal network there is not need to use port mapping (-p option on cli or the port field in dockerman templates). When communicating via the same custom docker network containers have access to all of each others ports. Port mappings are just for making ports accessible externally on the docker host.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.