# Turns your docker server into a manager of the Docker Swarm
$ docker swarm init
# Turns off docker swarm
$ docker swarm leave -f
connect cli to manager run commands on control plane.
# Creates a docker stack. Deploys compose file to your cluster
$ docker stack deploy -c docker-compose.yml csv-merger
# Removes a created docker stack
$ docker stack rm csv-merger
# Create network
$ docker network create --driver overlay portfolio-network
# View all networks
$ docker network ls
# Create a config file within the cluster database
$ docker config create <config-name> <path-to-config-file>
$ docker config inspect --pretty <config-name>
$ docker config ls
# Create a config file within the cluster database
$ docker secret create <secret-name> <path-to-secret-file>
$ docker secret inspect --pretty <secret-name>
$ docker secret ls
version: "3.7"
services:
products-db:
image: ...
ports:
- ...
environment:
- ...
config:
- source: <config-name>
target: <path-to-config-file>
secrets:
- source: <secret-name>
target: <path-to-secret-file>
mode: 0400
configs:
<config-name>:
external: true
secrets:
<secret-name>:
external: true
# List nodes in the swarm
$ docker node ls
# Add worker to cluster
$ docker swarm join-token worker
# Add manager to control plane
$ docker swarm join-token manager
# list services
$ docker service ls
# list stacks
$ docker stack ls
# list networks
$ docker network ls
# list containers
$ docker ps
-
Node - a single physical or virtual machine that is part of the swarm cluster. A node can either me a manager or a worker node.
-
Manger Node - These nodes are responsible for managing the state of the swarm, scheduling tasks, and maintaining the desired state of the cluster. There is usually one or more manager nodes in a swarm for high availability and fault tolerance. Manager nodes are also responsible for coordinating the worker nodes.
-
Worker Node - These nodes are responsible for executing the tasks that are assigned to them by the manager nodes. Worker nodes do not participate in the decision-making process; instead, they run the services and tasks as instructed by the manager nodes
-
Docker Swarm Cluster - a group of interconnected nodes (physical or virtual machines) that work together to manage and run containerized applications
-
Control Plane - primary consisting of manager nodes, this is responsible for managing the overal state and behavior of the cluser. Scheduling, monitoring and orchestrating task and services across the cluster.
-
Services - a higher-level abstraction that represents a group of containers running the same application or performing the same function. First class objects
-
Stacks - a higher-level abstraction that allows you to define and manage a group of interrelated services, networks, and volumes as a single unit. A stack is essentially a blueprint for deploying a multi-service application in a Docker Swarm cluster.
When in swarm connect CLI to manager and run commands on the control plane
- Deploying Containerized Applications by Elton Stoneman