Docker Containerization Docker Swarm and Orchestration 4 — Questions and Answers
Question 1: What command displays the live log output from all tasks of a Swarm service?
- docker service logs <service> (Correct answer)
- docker swarm logs <service>
- docker node logs <service>
- docker container logs --swarm <service>
Correct answer: docker service logs <service>
The 'docker service logs' command aggregates and streams log output from all running tasks of the specified service.
Question 2: Which flag limits the CPU resources available to each task in a Swarm service?
- --limit-cpu (Correct answer)
- --cpu-shares
- --cpuset-cpus
- --cpu-quota
Correct answer: --limit-cpu
The --limit-cpu flag sets a hard CPU limit (in fractions of a core) that each task in the service is not allowed to exceed.
Question 3: In Docker Swarm, what is the role of the 'ingress' network?
- It implements the routing mesh that distributes external traffic to service tasks (Correct answer)
- It connects manager nodes for Raft consensus communication
- It provides encrypted communication between worker nodes
- It isolates services within a stack from external access
Correct answer: It implements the routing mesh that distributes external traffic to service tasks
The ingress overlay network powers the Swarm routing mesh, allowing any node to accept traffic on a published port and route it to an available task.
Question 4: What happens when you run 'docker stack deploy' with an updated compose file?
- It performs a rolling update on changed services and leaves unchanged services running (Correct answer)
- It tears down all services in the stack and redeploys from scratch
- It creates new services for changes but does not update existing services
- It fails with an error if the stack already exists
Correct answer: It performs a rolling update on changed services and leaves unchanged services running
Re-running 'docker stack deploy' with an updated file applies changes incrementally — it updates modified services via rolling updates without restarting unchanged ones.
Question 5: Which Swarm service constraint targets only nodes that are Swarm manager nodes?
- --constraint 'node.role==manager' (Correct answer)
- --constraint 'node.type==manager'
- --constraint 'swarm.role==manager'
- --placement 'manager'
Correct answer: --constraint 'node.role==manager'
The built-in 'node.role' constraint can be set to 'manager' or 'worker' to restrict where a service's tasks are scheduled.
Question 6: What is the minimum recommended number of manager nodes for a highly available production Swarm?
- 3 (Correct answer)
- 1
- 2
- 5
Correct answer: 3
Three manager nodes are the minimum for high availability — they can tolerate one manager failure while still maintaining quorum.
Question 7: What does the 'docker node ls' command show?
- A list of all nodes in the Swarm with their status, availability, and role (Correct answer)
- The running containers on the current node only
- All services deployed across the Swarm cluster
- Network interfaces configured on each Swarm node
Correct answer: A list of all nodes in the Swarm with their status, availability, and role
The 'docker node ls' command lists all nodes registered in the Swarm cluster, including their ID, hostname, status, availability, and manager/worker role.
What command displays the live log output from all tasks of a Swarm service?