Docker Community Forums

Share and learn in the Docker community.

How to restrict access of <port> for all interfaces except eth0

I am running a service inside docker container which is running on host [“network_mode”: “host”] mode.
I want to restrict the access of from all available interfaces except “eth0”. Is there any way to do the same through docker-compose?


No, since you’re using “host”, its like the service is running on the host itself, so if you want to restrict access, you need to create some iptables rules

I see. thanks for quick reply… Would you please tell me, how to write a rule for iptable to block some port for all interfaces except one (lets say eth0) ??
Thanks in advance !

Hi again.

Im sorry but im not that sharp on iptables rules.

Is “host mode” a requirement? because its possible to use bridge mode, only to map to a single interface/ip