Docker Swarm resource management

Docker Swarm yes Docker One of the official three swordsmen project , provide Docker Container cluster service , yes Docker Core solution for official support of container cloud ecology .

Use it , Users can add multiple Docker Host packaged as a single large virtual Docker host , Quickly build a container cloud platform .

be careful :Docker1.12.0 Later version ,Swarm The module is already embedded Docker engine , become Docker Subcommand docker
swarm, Most users have already started using it Swarm modular ,Docker engine API Has been deleted Docker Swarm.

Basic concepts

Swarm It's using SwarmKit Constructed Docker Built in engine ( Primordial ) Cluster management and choreography tool . use Swarm Before clustering, you need to understand the following concepts .

node

function Docker Can initiate an Swarm Cluster or join an existing Swarm colony , It works like this Docker The host becomes a Swarm Nodes of the cluster (node).

Nodes are divided into management (manager) Nodes and work (worker) node .

* Management nodes are used for Swarm Cluster management ,docker swarm Collection can only be executed in the management node .
* The work node is the task execution node , The management node will serve (service) Issue to work node for execution .
The relationship between management node and work node in cluster

Services and tasks

task (Task) yes Swarm The smallest scheduling unit in , For now, it's a single container .
service (Services) A collection of tasks , The service defines the properties of the task .

There are two modes of service :

* replicated services Run a specified number of tasks on each work node according to certain rules .
* global services Each work node runs a task
Two modes passed docker service create Of --mode Parameter assignment

container , task , Service relationship

establish Swarm colony

understand Swarm The cluster is composed of management node and work node , We create a minimum with one management node and two work nodes Swarm colony .

Initialize cluster

use docker swarm init Initialize one locally Swarm colony .
docker swarm init --advertise-addr 192.168.1.1
If your Docker The host has multiple network segments , Have multiple IP, Must be used --advertise-addr appoint IP. implement docker swarm
init The node of the command automatically becomes the management node .

be careful : use docker swarm init

Add work node

On the other two servers, add the output from the previous step when creating the management node swarm The complete set of clusters
docker swarm join \ --token
SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-1awxwuwd3z9j1z3puu7rcgdbx
\ 192.168.1.1:2377
View cluster

Use in the management node docker node ls View cluster .
docker node ls

Deployment Services

use docker service Command to manage Swarm Services in cluster , This command can only be run on the management node .

New service

Creating a good Swarm Running in cluster nginx service
docker service create --replicas 3 -p 80:80 --name nginx nginx:latest

Now we use browsers , Enter any node IP, You can see nginx Default page .

View services

View current Swarm Services running in clusters
docker service ls
View the details of a service
docker service ps nginx
View the log of a service
docker service logs nginx
Delete service

from Swarm Remove a service from the cluster
docker service rm nginx
resource management

Front use Docker
Swarm Quickly build a minimum cluster , You can also deploy services on a cluster , But you'll find out swarm There is no unified portal to view the resource usage of a node . At this time, we can use graphical management tools Portainer Help us manage swarm colony .

Portainer yes Docker Graphical management tool of , The panel provides status , Rapid deployment of application template , Basic operation of container mirror network data volume ( Including upload and download images , Create container and so on ), Event log display , Container console operation ,Swarm Centralized management and operation of clusters and services , Login user management and control functions . The function is very comprehensive , It can basically meet all the requirements of container management in small units .

Portainer Cluster operation

download Portainer image
# What are the current queries Portainer image docker search portainer docker pull portainer/portainer
install Portainer( Management node )
docker run -d -p 9000:9000 \ --name portainer --restart=always \ -v
/var/run/docker.sock:/var/run/docker.sock \ portainer/portainer

Portainer to configure

Set administrator account password

Portainer Interface content

Technology