DCA · Question #19
What behavior is expected when a service is created with the following command: 'docker service create --publish 8000:80 nginx'
The correct answer is A. All nodes in the cluster will listen on port 8080 and forward to port 80 in the container. In Docker Swarm, when a service publishes a port with host_port:container_port, all manager and worker nodes in the cluster listen on the specified host_port and route traffic to the container's container_port.
Question
What behavior is expected when a service is created with the following command:
'docker service create --publish 8000:80 nginx'
Options
- AAll nodes in the cluster will listen on port 8080 and forward to port 80 in the container.
- BOnly a single node in the cluster will listen on port 8080 and forward to port 80 in the container.
- CAll nodes in the cluster will listen on port 80 and forward to port 8080 in the container.
- DOnly a single node in the cluster will listen on port 80 and forward to port 8080 in the container.
How the community answered
(39 responses)- A92% (36)
- C3% (1)
- D5% (2)
Why each option
In Docker Swarm, when a service publishes a port with `host_port:container_port`, all manager and worker nodes in the cluster listen on the specified `host_port` and route traffic to the container's `container_port`.
With `docker service create --publish 8000:80 nginx`, Docker Swarm's routing mesh (Ingress network) ensures that every node in the Swarm cluster listens on host port 8000. When traffic arrives on any node at port 8000, the routing mesh forwards it to port 80 of a healthy `nginx` service task, regardless of which node the task is running on.
The Docker Swarm routing mesh ensures that *all* nodes in the cluster listen on the published port, not just a single node, providing high availability and load balancing.
The command `--publish 8000:80` maps host port 8000 to container port 80, not the other way around.
This option is incorrect because the mapping is reversed and the routing mesh involves all nodes, not just a single one.
Concept tested: Docker Swarm routing mesh and port publishing
Source: https://docs.docker.com/engine/swarm/ingress/
Topics
Community Discussion
No community discussion yet for this question.