Build docker swarm clusters from scratch
Check node Docker configuration
1. Open the Docker configuration file (example CentOS 7)
Vim/etc/sysconfig/docker
2. Add-H tcp://0.0.0.0:2375 to options
options= '-g/cutome-path/docker-h tcp://0.0.0.0:2375 '
3. CentOS6.6 need to add the-H unix:///var/run/docker.sock separately
Options= '-g/mnt/docker-h tcp://0.0.0.0:2375-h unix:///var/run/docker.sock '
Install swarm for A and B nodes respectively
$ Docker Pull Swarm
Generate a cluster token (once)
$ docker Run--RM swarm create
6856663cdefdec325839a4b7e1de38e8
Where 6856663cdefdec325839a4b7e1de38e8 is the token that we are going to create the cluster
Adding nodes A, b to the cluster
$ docker run-d swarm join--addr=192.168.20.1:2375 Token://6856663cdefdec325839a4b7e1de38e8
$ docker run-d swarm join--addr=192.168.20.2:2375 Token://6856663cdefdec325839a4b7e1de38e8
This command does not return immediately after execution, we manually return it via CTRL + C.
List cluster A, B nodes
$ docker Run--RM swarm list Token://6856663cdefdec325839a4b7e1de38e8
192.168.20.1:2375
192.168.20.2:2375
Cluster Management:
Open the hypervisor on any host A, B, or C (c:192.168.20.3). For example, the C host is turned on:
$ docker run-d-P 8888:2375 Swarm manage Token://6856663cdefdec325839a4b7e1de38e8
Now you can manage cluster A, B on host C:
$ docker-h 192.168.20.3:8888 Info
$ docker-h 192.168.20.3:8888 PS
$ docker-h 192.168.20.3:8888 Logs ...
Running containers on a cluster
$ docker-h 192.168.20.3:8888 run-d--name web1 nginx
$ docker-h 192.168.20.3:8888 run-d--name web2 nginx
$ docker-h 192.168.20.3:8888 run-d--name web3 nginx
$ docker-h 192.168.20.3:8888 run-d--name web4 nginx
$ docker-h 192.168.20.3:8888 run-d--name web5 nginx
View containers within clusters A, b
$ docker-h 192.168.20.3:8888 ps-a
Build docker swarm clusters from scratch