web-dev-qa-db-ja.com

ポートをローカルホストのみに公開するように作成されていますが、Dockerサービスは公開されています

1つのサービスを作成し、Dockerスウォームノードの1つでローカルホストでのみ実行するように公開しましたが、サービスに公開するのは簡単すぎます。

Dockerスタックを削除して再デプロイしましたが、それでも同じ問題が発生します。

これが私のdocker-compose.ymlです。スタックにサービスをデプロイするために使用しました

version: "3"
networks:
    api-net:
        ipam:
            config:
                - subnet: 10.0.10.0/24

services:
    health-api:
        image: myprivateregistry:5000/healthapi:qa
        ports:
            - "127.0.0.1:9010:9010"
        networks:
            - api-net
        depends_on:
            - config-server
        deploy:
            mode: replicated
            replicas: 1
            placement:
                constraints:
                    - node.role == manager

それが問題だとは思わないので、依存するサービスを追加していません。

DockerSwarmモードではサポートされていないと言う人はほとんどいません。その場合の解決策よりも。

15

引用 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インターフェイスにバインドされます。入力ネットワークを介して外部に公開されたポートに接続します。

5
gesellix