Docker Containerization Docker Swarm and Orchestration 5 — Questions and Answers
Question 1: How do you remove a node from a Docker Swarm cluster from a manager node?
- docker node rm <node-id> (Correct answer)
- docker swarm leave --node <node-id>
- docker node delete <node-id>
- docker swarm remove <node-id>
Correct answer: docker node rm <node-id>
Running 'docker node rm <node-id>' on a manager removes the specified node from the Swarm cluster; the node must have left the swarm first.
Question 2: What is the purpose of the '--reserve-memory' flag when creating a Swarm service?
- It reserves a guaranteed minimum amount of memory for each task (Correct answer)
- It sets a hard cap on the maximum memory a task can use
- It pre-allocates memory on the node before the task starts
- It configures swap memory limits for the container
Correct answer: It reserves a guaranteed minimum amount of memory for each task
The --reserve-memory flag tells the Swarm scheduler to only place tasks on nodes with at least that much free memory, acting as a soft reservation.
Question 3: When deploying a Docker stack with 'docker stack deploy', which file format is required?
- Docker Compose file (version 3 or higher) (Correct answer)
- Dockerfile with multi-stage build syntax
- Kubernetes YAML manifest
- Docker run command exported as JSON
Correct answer: Docker Compose file (version 3 or higher)
Docker stack deploy requires a Compose file in version 3 format, which supports Swarm-specific 'deploy' keys ignored by plain docker-compose.
Question 4: What is the purpose of the 'docker swarm join-token worker' command?
- Displays the token and command needed to add a new worker node to the Swarm (Correct answer)
- Creates a new worker token and rotates the existing one
- Lists all workers that joined using the current token
- Revokes access for workers using the current join token
Correct answer: Displays the token and command needed to add a new worker node to the Swarm
Running 'docker swarm join-token worker' on a manager outputs the exact 'docker swarm join' command with the current token needed to add a new worker.
Question 5: Which Swarm feature ensures that a service always maintains its desired number of replicas even if tasks fail?
- Reconciliation loop (Correct answer)
- Health check restart policy
- Node heartbeat monitor
- Task scheduling queue
Correct answer: Reconciliation loop
Swarm's reconciliation loop continuously compares the desired state (replica count) with the observed state and creates replacement tasks when needed.
Question 6: What is the effect of running 'docker swarm init --advertise-addr <IP>' on a node?
- Initializes a new Swarm and advertises the specified IP for other nodes to join (Correct answer)
- Starts the Swarm routing mesh and binds it to the given IP address
- Updates the manager's advertised address in an existing cluster
- Configures the Swarm load balancer to use the specified IP as the VIP
Correct answer: Initializes a new Swarm and advertises the specified IP for other nodes to join
The --advertise-addr flag specifies the IP address the manager node will advertise to other nodes for API and overlay network communication during Swarm initialization.
Question 7: What does 'docker service scale web=5' accomplish?
- Sets the replica count for the 'web' service to 5 tasks (Correct answer)
- Limits the 'web' service to run on 5 nodes maximum
- Scales CPU and memory resources for each web task by a factor of 5
- Creates 5 additional replicas on top of the current count
Correct answer: Sets the replica count for the 'web' service to 5 tasks
The 'docker service scale' command sets the desired number of replicas for a service to the specified value, creating or removing tasks as needed.
How do you remove a node from a Docker Swarm cluster from a manager node?