简体   繁体   中英

Publish port in Docker Swarm host network

I created a docker swarm cluster with docker-18.03.1-ce.

When I deploy kafka container, I see code in stack.yml like this:

  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. This means that common networking flags like -p and --icc have no meaning for the host driver. They are ignored.'

I am confused whether published ports will take effect in Swarm host network?

Does anyone know about this?

I find the answer by myself from docker's network architecture article( 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. It publishes port 8080 locally on the hosts where these two containers are running. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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