Docker Swarm is a tool that lets you manage a group of Docker engines as a single virtual system. It helps you deploy and scale services easily across multiple machines.
Click to reveal answer
beginner
How do you initialize a Docker Swarm on a manager node?
You run the command docker swarm init on the machine you want to be the manager. This sets up the swarm and makes that node the leader.
Click to reveal answer
beginner
What command deploys a new service in Docker Swarm?
Use docker service create followed by options and the image name. For example, docker service create --name myweb nginx deploys an Nginx service named 'myweb'.
Click to reveal answer
beginner
What does the --replicas option do when deploying a service?
It sets how many copies (instances) of the service you want running. For example, --replicas 3 runs three copies of the service.
Click to reveal answer
intermediate
How can you update a running service in Docker Swarm?
Use docker service update with options to change the service. For example, docker service update --replicas 5 myweb changes the number of replicas to 5.
Click to reveal answer
Which command initializes a Docker Swarm manager node?
Adocker swarm init
Bdocker service create
Cdocker swarm join
Ddocker container run
✗ Incorrect
The command docker swarm init sets up the current node as a Swarm manager.
What does the command docker service create --replicas 4 nginx do?
ARemoves 4 nginx containers
BCreates 1 container running nginx
CCreates 4 containers running nginx as a service in Swarm
DUpdates an existing nginx service to 4 replicas
✗ Incorrect
The command creates a new service with 4 replicas of the nginx container.
How do you add a worker node to an existing Docker Swarm?
Adocker swarm init
Bdocker swarm join with the manager's token and IP
Cdocker service create
Ddocker container start
✗ Incorrect
Worker nodes join the swarm using docker swarm join with the manager's join token and IP address.
Which command shows the list of services running in a Docker Swarm?
Adocker swarm ps
Bdocker container ls
Cdocker node ls
Ddocker service ls
✗ Incorrect
docker service ls lists all services deployed in the swarm.
What happens if you scale a service to zero replicas?
AAll service tasks stop running
BOne task keeps running
CThe service is deleted
DThe service restarts automatically
✗ Incorrect
Setting replicas to zero stops all running tasks of that service.
Explain the steps to deploy a new service in Docker Swarm from scratch.
Think about setting up the swarm first, then adding nodes, then deploying the service.
You got /4 concepts.
Describe how to update the number of replicas for a running service in Docker Swarm.
Focus on the command that changes service settings without redeploying.
You got /3 concepts.
Practice
(1/5)
1. What does the docker service create command do in Docker Swarm?
easy
A. It deploys a new service across the Swarm cluster.
B. It removes an existing service from the Swarm.
C. It lists all running containers on a single node.
D. It initializes a new Swarm cluster.
Solution
Step 1: Understand the purpose of docker service create
This command is used to deploy a new service that runs containers across the Swarm cluster nodes.
Step 2: Differentiate from other commands
Removing services uses docker service rm, listing containers uses docker ps, and initializing Swarm uses docker swarm init.
Final Answer:
It deploys a new service across the Swarm cluster. -> Option A
Quick Check:
docker service create = deploy service [OK]
Hint: Create services to deploy apps on many nodes [OK]
Common Mistakes:
Confusing service creation with Swarm initialization
Mixing service removal with creation
Thinking it lists containers instead of services
2. Which of the following is the correct syntax to create a service with 3 replicas and publish port 80 to 8080?
easy
A. docker service create --replicas 3 --publish 8080:80 myimage
B. docker service create --publish 3 --replicas 80:8080 myimage
C. docker service create --replicas=3 --publish=80:8080 myimage
D. docker service create --replicas 3 --publish 80:8080 myimage
Solution
Step 1: Check correct option format for replicas and publish
The correct syntax uses --replicas 3 and --publish 8080:80 to map port 8080 on the host to port 80 in the container.
Step 2: Validate port mapping order and syntax
Port mapping is hostPort:containerPort, so 8080:80 is correct. Options B, C, and D have wrong order or syntax.
Final Answer:
docker service create --replicas 3 --publish 8080:80 myimage -> Option A
Quick Check:
Replicas and publish flags syntax = docker service create --replicas 3 --publish 8080:80 myimage [OK]
Hint: Use --replicas N and --publish hostPort:containerPort [OK]
Common Mistakes:
Reversing port numbers in --publish
Using equal signs incorrectly
Mixing replicas and publish values
3. What will be the output of the command docker service ls after running docker service create --name webapp --replicas 2 --publish 80:80 myimage:latest?
medium
A. Error: service not found
B. No services found
C. ID NAME MODE REPLICAS IMAGE PORTS
abc123 webapp replicated 2/2 myimage:latest *:80->80/tcp
D. ID NAME MODE REPLICAS IMAGE PORTS
abc123 webapp global 1/2 myimage:latest *:80->80/tcp
Solution
Step 1: Understand docker service ls output format
This command lists services with columns: ID, NAME, MODE, REPLICAS, IMAGE, PORTS.
Step 2: Match service details with created service
Since the service webapp has 2 replicas in replicated mode, the REPLICAS column shows 2/2. The ports show mapping like *:80->80/tcp.
Final Answer:
ID NAME MODE REPLICAS IMAGE PORTS
abc123 webapp replicated 2/2 myimage:latest *:80->80/tcp -> Option C
Quick Check:
Service list shows replicas count correctly [OK]
Hint: Replicas show as running/desired in service list [OK]
Common Mistakes:
Expecting 'global' mode instead of 'replicated'
Thinking no services appear after creation
Confusing error messages with normal output
4. You ran docker service create --replicas 3 --publish 80:80 myimage but only 1 replica is running. What is the likely cause?
medium
A. The image name is incorrect causing failure.
B. The command syntax is invalid and service was not created.
C. The port mapping syntax is wrong and blocks replicas.
D. Swarm has only one node available to run the replicas.
Solution
Step 1: Check cluster node availability
If only one node is in the Swarm, it can run only one replica at a time if resources are limited or constraints exist.
Step 2: Verify command correctness and image
The command syntax and image name are valid, so the issue is not syntax or image error.
Final Answer:
Swarm has only one node available to run the replicas. -> Option D
Quick Check:
Replica count depends on node availability [OK]
Hint: Check number of nodes to match replica count [OK]
Common Mistakes:
Assuming port syntax blocks replicas
Blaming image name without error messages
Thinking syntax error stops service creation
5. You want to deploy a service named api with 4 replicas, publish port 5000, and ensure it restarts automatically on failure. Which command is correct?
hard
A. docker service create --name api --replicas 4 --publish 5000:5000 myapiimage --restart-condition on-failure
B. docker service create --name api --replicas 4 --publish 5000:5000 --restart-condition on-failure myapiimage
C. docker service create --name api --replicas 4 --publish 5000:5000 --restart-condition failure myapiimage
D. docker service create --name api --replicas 4 --publish 5000:5000 --restart on-failure myapiimage
Solution
Step 1: Identify correct restart flag for services
Docker Swarm uses --restart-condition to specify restart behavior, such as on-failure.
Step 2: Check option placement and syntax
Options must be before the image name. docker service create --name api --replicas 4 --publish 5000:5000 --restart-condition on-failure myapiimage correctly places --restart-condition on-failure before the image name. Options B and C use invalid flags or values. docker service create --name api --replicas 4 --publish 5000:5000 myapiimage --restart-condition on-failure places the flag after the image name, which is invalid.
Final Answer:
docker service create --name api --replicas 4 --publish 5000:5000 --restart-condition on-failure myapiimage -> Option B
Quick Check:
Use --restart-condition on-failure before image [OK]
Hint: Use --restart-condition on-failure before image name [OK]
Common Mistakes:
Using --restart instead of --restart-condition
Placing flags after image name
Using invalid restart condition values
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.