一步步创建第一个Docker App —— 3. 创建一个集群Swarm
原文:https://docs.docker.com/engine/getstarted-voting-app/create-swarm/
初始化集群 Swarm
1. 使用 ssh 命令登录 manager 虚拟机:
PS
C:\Users\Administrator> docker
-machine
ssh manager
## .
## ## ## ==
## ## ## ## ## ===
/
""
""
""
""
""
""
""
""
"\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\_______/
_ _ ____ _ _
| |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __
|
'_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '
__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 1.13.1, build HEAD : b7f6033 - Wed Feb 8 20:31:48 UTC 2017
Docker version 1.13.1, build 092cba3
docker@manager:~$
2. 初始化集群 Swarm
使用命令:
docker swarm init -
-advertise
-addr
<MANAGER
-IP
>
docker@manager:~$ docker swarm init -
-advertise
-addr
192.168.0.9
Swarm initialized: current node (j1kqy5hzlaljw9camxjufvxxo) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join \
-
-token
SWMTKN-1-5p9gvdvpdagep4v6wea2lgfnzhzktsmvdzb3rh5h3zv0utyzza-22q2wamqy4ypd3glvzddczyto \
192.168.0.9:2377
To add a manager to this swarm, run
'docker swarm join-token manager'
and follow the instructions.
docker@manager:~$
将 worker node 添加到集群 swarm
1. 登录到 worker 虚拟机
PS
C:\Users\Administrator> docker
-machine
ssh worker
## .
## ## ## ==
## ## ## ## ## ===
/
""
""
""
""
""
""
""
""
"\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\_______/
_ _ ____ _ _
| |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __
|
'_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '
__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 1.13.1, build HEAD : b7f6033 - Wed Feb 8 20:31:48 UTC 2017
Docker version 1.13.1, build 092cba3
docker@worker:~$
2. 在 worker machine 上,使用之前创建集群后显示的join 命令:
docker@worker:~$ docker swarm join \
> -
-token
SWMTKN-1-5p9gvdvpdagep4v6wea2lgfnzhzktsmvdzb3rh5h3zv0utyzza-22q2wa
mqy4ypd3glvzddczyto \
> 192.168.0.9:2377
This node joined a swarm as a worker.
docker@worker:~$
如果忘记了该join命令,可以在 manager node 中,执行命令:
docker swarm join-token worker
docker@manager:~$ docker swarm join
-token
worker
To add a worker to this swarm, run the following command:
docker swarm join \
-
-token
SWMTKN-1-5p9gvdvpdagep4v6wea2lgfnzhzktsmvdzb3rh5h3zv0utyzza-22q2wamqy4ypd3glvzddczyto \
192.168.0.9:2377
从而重新获得join命令
列出集群swarm中的节点nodes
ssh 到 manager 虚拟机,并执行命令:
docker node ls
docker@manager:~$ docker node
ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
1jg0u7j30ws81wpkounabtzon worker Ready Active
j1kqy5hzlaljw9camxjufvxxo * manager Ready Active Leader