Docker Community Forums

Share and learn in the Docker community.

Attached multiple networks : assign hostname per network?


(Daledude) #1

I have multiple networks attached to a service (–network name=private,alias=private --network name=public,alias=public) and need a way to resolve the “public” and “private” ip’s assigned to the container from within the container. Resolving using the alias “public” or “private” will return all A records for all tasks in a service. I just need the ip’s for the current container.

My app needs to listen on different ports for both networks but NOT on all networks (no 0.0.0.0).

I can’t figure out how to assign an env variable or hostname per interface. Whether or not I used --hostname with service create it puts the same hostname for both ip’s in /etc/hosts.
192.168.0.10 my-hostname
8.2.6.4 my-hostname

Thank you in advance!