compose icon indicating copy to clipboard operation
compose copied to clipboard

feature: Allow specifing an interface instead of an IP address when doing port-mapping

Open oliv3r opened this issue 2 years ago • 1 comments

Description

Currently, a compose file (and docker itself naturally as well) can define an IP address to map a port to the outside. This is fine, however compose files tend to be more static.

if I have an nginx proxy, and I want to only bind it to the externally facing network interface, I can do that by using 0.0.0.0. However, this now prevents me from using these ports on any internal interface. The only way around this, is to manually specify the IP address of the desired interface. For static IP addresses this is not a huge issue, but for more dynamic IP addresses in nature (dhcp from an ISP for example) this becomes problematic, as a compose file may be stored in a git repository, so changing the IP is not a simple matter of scripting something, it requires a whole update cycle. Also its not so 'clean'.

Instead, allow us to specify an interface instead, so a port mapping would look like ports: - "ppp0:443:443/tcp" for example.

Internally, this does have one potentially big side effect, dockerd now needs to monitor IP changes on the interface, as a change in IP address, means a new iptables rule needs to be inserted, but more importantly, the old one needs to be removed. A 'quick and dirty' is to generate an event, and force an exit of the container, which could trigger a restart. Not ideal, but if the IP changes, loss of service has happened already anyway.

oliv3r avatar Jun 09 '23 07:06 oliv3r

Docker Compose can't offer such a feature until the Docker Engine does, please open a feature request on https://github.com/moby/moby

ndeloof avatar Dec 21 '23 09:12 ndeloof