Docker swarm common command - mnhmilu/poc-kubernets GitHub Wiki

Sure! Docker Swarm is a container orchestration platform that allows you to create and manage a cluster of Docker nodes. Here are some common Docker Swarm-related commands and concepts:

  1. Initialize a Swarm:
docker swarm init
  1. Join a node to the Swarm (run this command on other nodes to add them to the Swarm):
docker swarm join --token <TOKEN> <MANAGER_IP>:<MANAGER_PORT>
  1. Create a service (replicated or global mode):
docker service create --replicas <REPLICAS> --name <SERVICE_NAME> <IMAGE_NAME>
docker service create --mode global --name <SERVICE_NAME> <IMAGE_NAME>
  1. List all services in the Swarm:
docker service ls
  1. List tasks of a service:
docker service ps <SERVICE_NAME>
  1. Scale a service (increase or decrease the number of replicas):
docker service scale <SERVICE_NAME>=<REPLICAS>
  1. Update a service with a new image or configuration:
docker service update --image <NEW_IMAGE_NAME> <SERVICE_NAME>
  1. Remove a service from the Swarm:
docker service rm <SERVICE_NAME>
  1. List all nodes in the Swarm:
docker node ls
  1. Inspect a specific node:
docker node inspect <NODE_ID>
  1. Drain a node (prevent new tasks from being scheduled on the node):
docker node update --availability drain <NODE_ID>
  1. Promote a worker node to manager status:
docker node promote <NODE_ID>
  1. Demote a manager node to worker status:
docker node demote <NODE_ID>
  1. Leave the Swarm (run on a node to remove it from the Swarm):
docker swarm leave
  1. Leave the Swarm and remove the node from the manager:
docker swarm leave --force

These are some of the common commands used to interact with Docker Swarm. Docker Swarm provides a simple and powerful way to manage containerized applications in a cluster of Docker nodes.

⚠️ **GitHub.com Fallback** ⚠️