Docker Containerization Docker Swarm and Orchestration 2 — Questions and Answers
Question 1: What command promotes an existing Swarm worker node to a manager?
- docker node promote <node> (Correct answer)
- docker swarm promote <node>
- docker node update --role manager <node>
- docker manager add <node>
Correct answer: docker node promote <node>
The 'docker node promote <node>' command changes a worker node's role to manager in a Docker Swarm cluster.
Question 2: Which Swarm placement constraint would restrict a service to only run on nodes labeled 'env=production'?
- --constraint 'node.labels.env==production' (Correct answer)
- --filter 'label=env=production'
- --placement 'env:production'
- --reserve 'node.env=production'
Correct answer: --constraint 'node.labels.env==production'
Placement constraints use the syntax --constraint 'node.labels.<key>==<value>' to target nodes with specific labels.
Question 3: What happens to tasks on a Swarm node when it is set to 'drain' availability?
- Running tasks are rescheduled on other nodes (Correct answer)
- Tasks are paused and resumed when availability is restored
- Tasks continue running until they complete naturally
- Tasks are immediately deleted without rescheduling
Correct answer: Running tasks are rescheduled on other nodes
Setting a node to drain availability stops new tasks from being assigned and reschedules existing tasks to other available nodes.
Question 4: In Docker Swarm, what is a 'task' in the context of a service?
- A single running instance of a service container (Correct answer)
- The definition file for a service
- A health check job for a node
- A scheduled cron job within a service
Correct answer: A single running instance of a service container
A task is the atomic unit of scheduling in Swarm, representing one running container instance of a service replica.
Question 5: Which command updates a running Swarm service to use a new image version?
- docker service update --image <image>:<tag> <service> (Correct answer)
- docker service redeploy --image <image>:<tag> <service>
- docker service restart --version <tag> <service>
- docker swarm update --image <image>:<tag> <service>
Correct answer: docker service update --image <image>:<tag> <service>
The 'docker service update --image' command performs a rolling update of the service to use the specified image version.
Question 6: What is the default update parallelism in a Docker Swarm service?
- 1 task at a time (Correct answer)
- 2 tasks at a time
- All tasks simultaneously
- 10% of replicas at a time
Correct answer: 1 task at a time
By default, Docker Swarm updates one task at a time during a rolling update to minimize downtime.
Question 7: How does Docker Swarm handle secrets differently from environment variables?
- Secrets are stored encrypted in the Raft log and mounted as files in containers (Correct answer)
- Secrets are base64-encoded environment variables passed at runtime
- Secrets are stored in a separate SQLite database on each manager
- Secrets are injected into container memory without any persistent storage
Correct answer: Secrets are stored encrypted in the Raft log and mounted as files in containers
Swarm secrets are encrypted at rest in the Raft log and delivered to containers as temporary in-memory files at /run/secrets/.
What command promotes an existing Swarm worker node to a manager?