DCA · Question #17
Which of the following commands will create a swarm service which only listens on port 53 using the UDP protocol?
The correct answer is A. docker service create --name dns-cache -p 53:53/udp dns-cache. To create a Docker Swarm service that exposes a specific port using the UDP protocol, the --publish (or -p) flag must specify the protocol with /udp.
Question
Which of the following commands will create a swarm service which only listens on port 53 using the UDP protocol?
Options
- Adocker service create --name dns-cache -p 53:53/udp dns-cache
- Bdocker service create --name dns-cache -p 53:53 --service udp dns-cache
- Cdocker service create --name dns-cache -p 53:53 ..constraint networking.protocol.udp=true dns-
- Ddocker service create --name dns-cache -p 53:53 --udp dns-cache
How the community answered
(55 responses)- A89% (49)
- B4% (2)
- C2% (1)
- D5% (3)
Why each option
To create a Docker Swarm service that exposes a specific port using the UDP protocol, the `--publish` (or `-p`) flag must specify the protocol with `/udp`.
The `--publish` (or `-p`) flag in `docker service create` allows specifying the protocol (TCP or UDP) along with the port mapping. Using `-p 53:53/udp` correctly maps host port 53 to container port 53, explicitly for UDP traffic.
There is no `--service udp` option for `docker service create` to specify the network protocol.
While constraints are used for service placement, `networking.protocol.udp=true` is not a valid constraint for specifying the protocol of the published port.
There is no `--udp` option for `docker service create` to specify the network protocol for port publishing.
Concept tested: Docker Swarm service port publishing UDP
Source: https://docs.docker.com/engine/reference/commandline/service_create/#publish-ports--p
Topics
Community Discussion
No community discussion yet for this question.