Docker Swarm is a group of either physical or
virtual machines that are running the Docker application and that have been
configured to join together in a cluster. Once a group of machines have been
clustered together, you can still run the Docker commands that you're used to,
but they will now be carried out by the machines in your cluster.
The activities of the cluster are controlled by a
swarm manager, and machines that have joined the cluster are referred to as
nodes.
Docker swarm is a container orchestration tool,
meaning that it allows the user to manage multiple containers deployed across
multiple host machines.
The cluster management and orchestration features
embedded in the Docker Engine are built using Swarmkit.
A Node is an instance of the Docker engine participating in the
swarm.
Worker Nodes receive and execute tasks dispatched from manager nodes.
By default manager nodes also run services as worker nodes, but you can
configure them to run manager tasks exclusively and be manager-only nodes.
Manager nodes perform the orchestration and cluster
management functions required to maintain the desired state of the swarm.
The swarm manager can automatically assign the
service a PublishedPort or you can configure a PublishedPort for the service.
A Service is the definition of
tasks to execute on the manager or worker nodes. It is the central structure of
the swarm system and the primary root of user interaction with the swarm.
Node
Management:
- Initialize
a swarm: docker swarm init
- List
swarm nodes: docker node ls
Activate
a node (after maintenance):
docker node update
--availability active node_name
- List
services (manager node): docker service ls
- Describe
services (manager node): docker service ps service_name
- Inspect
a service: docker service inspect service_name
- Scale a
service: docker service scale service_name=N
- Remove
service: docker service rm service_name
- Deploy
stack from docker-compose file: docker stack deploy -c
docker-compose.yml stack_name
- List
stacks: docker stack ls
- List
stack services: docker stack services stack_name
- List
stack tasks: docker stack ps stack_name
- Remove
stack : docker stack rm stack_name
- List
networks: docker network ls
- Create
overlay network: docker network create -d overlay network_name
- Remove
network: docker network rm network_name
- Docker
stats: docker stats
- Service
logs: docker service logs service_name