Цитирование https://github.com/moby/moby/issues/32299#issuecomment-290978794:
On swarm mode, if you publish something (ports for stack deploy), it is published on the ingress network, and thus it is public. There is a few ways to get around, but putting kind/bug on that because we should at least warn people about that when doing a stack deploy with ports that have this notation (i.e. host:port:port).
To work around this, there is a few ways:
- first, you should publish mongo ports only if you want it to be public, otherwise, it is available through the name discovery bundle in docker (another container/service on the same network will be able to reach it through mongo dns name).
- If you want to publish it in the host and not in ingress (so not swarm public, just on the host it is running, same way as without swarm mode), you need to use ports expanded syntax.
... (example and some more details regarding the effect of the extended syntax).
Итак, причина - входная сеть Swarm, которая делает каждый порт общедоступным.Обходной путь с использованием расширенного синтаксиса не привязывается к интерфейсу обратной связи , а к интерфейсу 0.0.0.0
хоста, что по-прежнему является улучшением по сравнению с внешним портом через входную сеть.