Debug School

rakesh kumar
rakesh kumar

Posted on

List out the checklist of Docker Swarm Commands

Docker Swarm is a container orchestration tool that lets us manage multiple containers on multiple hosts. We can use Swarm to combine multiple Docker hosts into a single host for easier management and monitoring.

One of the key advantages of docker swarm is that the configuration of the docker services such as volume and network can be modified without the need to manually restart the service Docker will update the configuration, stop the service tasks with the out-of-date configuration, and create new ones matching the desired configuration

Tools to manage, scale, and maintain containerized applications are called orchestrators. Two of the most popular orchestration tools are Kubernetes and Docker Swarm

Image description

Initialize Swarm:

docker swarm init
Enter fullscreen mode Exit fullscreen mode

Expected Output:

Swarm initialized: current node (abc123) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-2nv3c4... 192.168.1.100:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
Enter fullscreen mode Exit fullscreen mode

This command initializes a new Docker Swarm on the current node and designates it as a manager.

2. Join Swarm as a Worker:

docker swarm join --token SWMTKN-1-2nv3c4... 192.168.1.100:2377
Enter fullscreen mode Exit fullscreen mode

Expected Output:

This node joined a swarm as a worker.
Enter fullscreen mode Exit fullscreen mode

This command joins the current node to an existing Docker Swarm as a worker.

3. Join Swarm as a Manager:

docker swarm join-token manager
Enter fullscreen mode Exit fullscreen mode

Expected Output:

To add a manager to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-2nv3c4... 192.168.1.100:2377
Enter fullscreen mode Exit fullscreen mode

This command generates a token and instructions for joining the Swarm as a manager.

4. Display Swarm Nodes:

docker node ls
Enter fullscreen mode Exit fullscreen mode

Expected Output:

Image description

This command lists all nodes in the Docker Swarm, including their status and availability.

5. Deploy a Service:

docker service create --name myservice myimage:1.0
Expected Output:

p2gs83bg2zdm9mtc8yjy9flxc
Enter fullscreen mode Exit fullscreen mode

This command deploys a Docker service named myservice using the specified image.

6. List Services:

docker service ls
Enter fullscreen mode Exit fullscreen mode

Expected Output:

Image description

This command lists all services running in the Docker Swarm.

7. Inspect a Service:

docker service inspect myservice
Enter fullscreen mode Exit fullscreen mode

Expected Output:

[    {        "ID": "p2gs83bg2zdm9mtc8yjy9flxc",        "Name": "myservice",        ...    }]
Enter fullscreen mode Exit fullscreen mode

This command provides detailed information about a specific Docker service (myservice).

8. Scale a Service:

docker service scale myservice=3
Enter fullscreen mode Exit fullscreen mode

Expected Output:

myservice scaled to 3 replicas
Enter fullscreen mode Exit fullscreen mode

This command scales the number of replicas for the myservice to 3.

9. Update a Service:

docker service update --image myimage:2.0 myservice
Enter fullscreen mode Exit fullscreen mode

Expected Output:

myservice
Enter fullscreen mode Exit fullscreen mode

This command updates the Docker service (myservice) to use a new image (myimage:2.0).

10. Remove a Service:

docker service rm myservice
Enter fullscreen mode Exit fullscreen mode

Expected Output:

myservice
Enter fullscreen mode Exit fullscreen mode

This command removes the Docker service named myservice.

11. Leave Swarm:

docker swarm leave
Enter fullscreen mode Exit fullscreen mode

Expected Output:

Node left the swarm.
Enter fullscreen mode Exit fullscreen mode

This command makes the current node leave the Docker Swarm.

12. Remove Swarm:

docker swarm leave --force
Enter fullscreen mode Exit fullscreen mode

Expected Output:

Node left the swarm.
Enter fullscreen mode Exit fullscreen mode

This command forcefully removes the current node from the Docker Swarm.

13. Display Swarm Info:

docker swarm info
Enter fullscreen mode Exit fullscreen mode

Expected Output:

Swarm: active
 NodeID: abc123
Enter fullscreen mode Exit fullscreen mode

This command displays information about the active Docker Swarm.

14. Show Join Tokens:

docker swarm join-token
Enter fullscreen mode Exit fullscreen mode

Expected Output:

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-2nv3c4... 192.168.1.100:2377
Enter fullscreen mode Exit fullscreen mode

This command shows tokens and instructions for joining nodes to the Docker Swarm.

These Docker Swarm commands cover a range of tasks, from initializing and managing nodes to deploying and scaling services within the Swarm. Adjust the examples based on your specific Swarm configuration and requirements.

Top comments (0)