Development tool -- docker--swarm -- cluster instance

Create cluster

Initialize cluster

Use docker swarm init to initialize a Swarm cluster locally.
At the same time, the node automatically becomes a management node.
If the host has multiple network cards and multiple IPS, you must use -- advertisement addr to specify the IP.

After initialization, the token added by other nodes will be given
$ docker swarm init --advertise-addr 192.168.99.100
Swarm initialized: current node (dxn1zf6l61qsb1josjja83ngz) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join \
    --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \
    192.168.99.100:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

Add work node

Use docker swarm join to join a node to a cluster.
Node joining as a manager node or worker node depends on passing the past token using the - token parameter.
Next, we use Docker machine to create a Docker host and add it to the cluster.

$ docker-machine create -d virtualbox worker1

$ docker-machine ssh worker1

docker@worker1:~$ docker swarm join \
    --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \
    192.168.99.100:2377

This node joined a swarm as a worker.

View cluster

Use docker nodes to view the current cluster
$ docker node ls
ID                            HOSTNAME   STATUS   AVAILABILITY   MANAGER STATUS
16w80jnqy2k30yez4wbbaz1l8     worker1     Ready     Active        
2gkwhzakejj72n5xoxruet71z     worker2     Ready     Active        
35kutfyn1ratch55fn7j3fs4x     worker3     Ready     Active        
a9r21g5iq1u6h31myprfwl8ln *   manager2    Ready     Active        Reachable
dpo7snxbz2a0dxvx6mf19p35z     manager1    Ready     Active        Leader
Now each node belongs to Swarm and is in standby mode.
Manager1 is the leader, work1 is the worker.

Deployment Services

New service

docker service create [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a service called nginx in the cluster.

$ docker service create --replicas 3 -p 80:80 --name nginx nginx:1.13.7-alpine

View services

Use docker service ls to view the services running in the current Swarm cluster.

$ docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE                 PORTS
kc57xffvhul5        nginx               replicated          3/3                 nginx:1.13.7-alpine   *:80->80/tcp

Use docker service ps to view the details of a service.

$ docker service ps nginx
ID                  NAME                IMAGE                 NODE                DESIRED STATE       CURRENT STATE                ERROR               PORTS
pjfzd39buzlt        nginx.1             nginx:1.13.7-alpine   swarm2              Running             Running about a minute ago
hy9eeivdxlaa        nginx.2             nginx:1.13.7-alpine   swarm1              Running             Running about a minute ago
36wmpiv7gmfo        nginx.3             nginx:1.13.7-alpine   swarm3              Running     

Use docker service logs to view the logs of a service.

$ docker service logs nginx
nginx.3.36wmpiv7gmfo@swarm3    | 10.255.0.4 - - [25/Nov/2017:02:10:30 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:58.0) Gecko/20100101 Firefox/58.0" "-"
nginx.3.36wmpiv7gmfo@swarm3    | 10.255.0.4 - - [25/Nov/2017:02:10:30 +0000] "GET /favicon.ico HTTP/1.1" 404 169 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:58.0) Gecko/20100101 Firefox/58.0" "-"
nginx.3.36wmpiv7gmfo@swarm3    | 2017/11/25 02:10:30 [error] 5#5: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 10.255.0.4, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.99.102"
nginx.1.pjfzd39buzlt@swarm2    | 10.255.0.2 - - [25/Nov/2017:02:10:26 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:58.0) Gecko/20100101 Firefox/58.0" "-"
nginx.1.pjfzd39buzlt@swarm2    | 10.255.0.2 - - [25/Nov/2017:02:10:27 +0000] "GET /favicon.ico HTTP/1.1" 404 169 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:58.0) Gecko/20100101 Firefox/58.0" "-"
nginx.1.pjfzd39buzlt@swarm2    | 2017/11/25 02:10:27 [error] 5#5: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 10.255.0.2, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.99.101"

Cluster load

scale
https://www.jianshu.com/p/9eb9995884a5

Delete service

Use docker service rm to remove a service from the Swarm cluster.
$ docker service rm nginx

compose

configuration management

Password

To configure

Reference resources

docker machine + docker swarm
https://www.jianshu.com/p/9eb9995884a5

Tags: Docker Nginx Mac OS X

Posted on Sun, 03 May 2020 08:14:30 -0400 by Niyati_1984