Docker Containerization Docker Swarm and Orchestration 3 — Questions and Answers
Question 1: What is the purpose of the '--publish mode=host' option when creating a Swarm service?
- It binds the port directly on the host without using the routing mesh (Correct answer)
- It publishes the service to the host's external DNS
- It enables host-mode networking for all inter-service communication
- It forces the container to share the host's network namespace
Correct answer: It binds the port directly on the host without using the routing mesh
Using mode=host bypasses the Swarm routing mesh and binds the port directly to the host node, meaning only nodes running the task accept traffic on that port.
Question 2: Which Raft consensus requirement must be met for a Swarm cluster to remain operational?
- A majority (quorum) of manager nodes must be reachable (Correct answer)
- All manager nodes must be reachable at all times
- At least one manager and one worker must be reachable
- At least two managers must be reachable regardless of total count
Correct answer: A majority (quorum) of manager nodes must be reachable
Swarm uses the Raft protocol, which requires a quorum — more than half of managers — to elect a leader and process cluster changes.
Question 3: What does the 'docker service rollback <service>' command do?
- Reverts the service to its previous configuration before the last update (Correct answer)
- Deletes the service and redeploys from the original image
- Rolls back only the failed tasks to their previous state
- Restarts all tasks without changing the service configuration
Correct answer: Reverts the service to its previous configuration before the last update
The rollback command reverts a service to the configuration it had before the most recent 'docker service update' was applied.
Question 4: In a Docker Swarm stack file, what does the 'deploy.mode: global' setting accomplish?
- Runs exactly one task on every node in the cluster (Correct answer)
- Distributes replicas evenly across all available nodes
- Runs the service only on manager nodes
- Schedules the service on nodes with the most available CPU
Correct answer: Runs exactly one task on every node in the cluster
Global mode ensures one instance of the service runs on every node in the swarm, useful for agents and monitoring daemons.
Question 5: What network driver does Docker Swarm use by default for multi-host service communication?
- overlay (Correct answer)
- bridge
- macvlan
- host
Correct answer: overlay
Overlay networks span multiple Docker hosts and are the default driver for Swarm services that need to communicate across nodes.
Question 6: How can you force a Swarm service to redistribute its tasks evenly across nodes after adding a new node?
- docker service update --force <service> (Correct answer)
- docker swarm rebalance <service>
- docker node balance <service>
- docker service redeploy --rebalance <service>
Correct answer: docker service update --force <service>
Running 'docker service update --force' causes Swarm to reschedule all tasks, which redistributes them across all available nodes including newly added ones.
Question 7: What is the effect of setting '--update-failure-action=rollback' on a Swarm service?
- Automatically reverts the service if an update task fails health checks (Correct answer)
- Pauses the update and waits for manual intervention when a task fails
- Immediately stops the rolling update and leaves failed tasks running
- Retries the failed task update three times before giving up
Correct answer: Automatically reverts the service if an update task fails health checks
Setting update-failure-action to rollback instructs Swarm to automatically revert the service to its previous state when an updated task fails.
What is the purpose of the '--publish mode=host' option when creating a Swarm service?