nerdexam
Docker

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.

Submitted by takeshi77· Apr 18, 2026Orchestration

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)
  • A
    92% (36)
  • C
    3% (1)
  • D
    5% (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`.

AAll nodes in the cluster will listen on port 8080 and forward to port 80 in the container.Correct

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.

BOnly a single node in the cluster will listen on port 8080 and forward to port 80 in the container.

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.

CAll nodes in the cluster will listen on port 80 and forward to port 8080 in the container.

The command `--publish 8000:80` maps host port 8000 to container port 80, not the other way around.

DOnly a single node in the cluster will listen on port 80 and forward to port 8080 in the container.

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

#Docker Swarm#Service Networking#Port Mapping#Routing Mesh

Community Discussion

No community discussion yet for this question.

Full DCA Practice