Port Problem in Portainer Docker Swarm

Hello, I have the following problem.in vain, I specify in the stack under the port that 127.0.0.1:port is still available from anywhere, not only locally. how can i fix this?

ports:
- “127.0.0.1:27017:27017”

Swarm services can not publish ports to a specific host ip, as their replicas can potentially be started on an arbitrary node.

You either need to switch to plain docker containers, by using docker compose deployments, or you will need to figure out the iptables rules that prevent access to the published port on all other host ips - you are pretty much on your own here.

1 Like