简体   繁体   English

在Docker Swarm主机网络中发布端口

[英]Publish port in Docker Swarm host network

I created a docker swarm cluster with docker-18.03.1-ce. 我使用docker-18.03.1-ce创建了一个docker swarm集群。

When I deploy kafka container, I see code in stack.yml like this: 部署kafka容器时,我在stack.yml中看到如下代码:

  kafka:
    image: wurstmeister/kafka:2.11-2.0.0
    ports:
      - target: 9094
        published: 9094
        protocol: tcp
        mode: host

But in docker's network architecture article( https://success.docker.com/article/networking ), it says 'With the host driver, Docker does not manage any portion of the container networking stack such as port mapping or routing rules. 但是在Docker的网络体系结构文章( https://success.docker.com/article/networking )中,它说:“使用主机驱动程序,Docker不会管理容器网络堆栈的任何部分,例如端口映射或路由规则。 This means that common networking flags like -p and --icc have no meaning for the host driver. 这意味着-p和--icc之类的通用网络标志对于主机驱动程序没有意义。 They are ignored.' 他们被忽略了。

I am confused whether published ports will take effect in Swarm host network? 我很困惑,发布的端口是否会在Swarm主机网络中生效?

Does anyone know about this? 有人知道吗?

I find the answer by myself from docker's network architecture article( https://success.docker.com/article/networking ): 我从Docker的网络架构文章( https://success.docker.com/article/networking )中找到了答案:

host mode port publishing exposes ports only on the host where specific service tasks are running. 主机模式端口发布仅在运行特定服务任务的主机上公开端口。 The port is mapped directly to the container on that host. 端口直接映射到该主机上的容器。 Only a single task of a given service can run on each host to prevent port collision. 给定服务的单个任务只能在每个主机上运行,​​以防止端口冲突。

$ docker service create --replicas 2 --publish mode=host,target=80,published=8080 nginx

host mode requires the mode=host flag. 主机模式需要mode = host标志。 It publishes port 8080 locally on the hosts where these two containers are running. 它在运行这两个容器的主机上本地发布端口8080。 It does not apply load balancing, so traffic to those nodes are directed only to the local container. 它不应用负载平衡,因此流向那些节点的流量仅定向到本地容器。 This can cause port collision if there are not enough ports available for the number of replicas. 如果没有足够数量的副本副本可用端口,则可能导致端口冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM