Docker Swarm Cheatsheet

These commands are used to manage a Docker Swarm cluster, create and manage Docker services, and manage Docker networks.
docker network create -d overlay collabnetcreates a new Docker overlay network named "collabnet".docker network lslists all the available Docker networks.docker network inspect collabnetinspects the details of the "collabnet" network.docker service create --name http --network collabnet --replicas 2 -p 80:80 ajeetraina/hellowhalecreates a new Docker service named "http" with 2 replicas, running the "ajeetraina/hellowhale" image and connected to the "collabnet" network. Port 80 is exposed on the host and maps to port 80 in the container.docker pslists all the running containers.curl your_machine_ip:80sends a request to the IP address "your_machine_ip" on port 80.docker service ps httpshows the status of the "http" service.docker service inspect --pretty httpinspects the details of the "http" service.docker node ps selfshows the tasks running on the current node.docker node ps $(docker node ls -q | head -n1)shows the tasks running on the first node in the cluster.docker service scale http=5scales the number of replicas of the "http" service to 5.curl your_machine_ip:80sends another request to the IP address "your_machine_ip" on port 80.docker service scale http=2scales the number of replicas of the "http" service back to 2.docker service create --name sleep-app ubuntu sleep infinitycreates a new Docker service named "sleep-app" with a single replica running the "ubuntu" image and running the "sleep infinity" command.docker service update --replicas 7 sleep-appupdates the number of replicas of the "sleep-app" service to 7.docker service lslists all the available Docker services.docker service ps sleep-appshows the status of the "sleep-app" service.docker service update --replicas 4 sleep-appupdates the number of replicas of the "sleep-app" service back to 4.docker node lslists all the nodes in the Swarm cluster.docker node update --availability drain worker2drains the node "worker2" so that no new tasks will be scheduled on it.docker node inspect --pretty worker2inspects the details of the "worker2" node.docker node update --availability active worker2reactivates the "worker2" node so that it can again receive tasks.docker service rm sleep-appremoves the "sleep-app" service.docker service lslists all the available Docker services.docker kill yourcontaineridkills the container with the ID "yourcontainerid".docker swarm leave --forceforces the current node to leave the Swarm cluster.docker swarm join-token managerretrieves the command to join the Swarm cluster as a manager.docker network create --driver=overlay --subnet=192.168.1.0/24 --gateway=192.168.1.100 myoverlay0creates network of overlay type with specified subnet and gateway.




