Build docker swarm clusters from scratch

Source: Internet
Author: User
Tags docker run docker swarm

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.