[root@master~]# docker swarm init --advertise-addr 192.168.63.217
To add a worker to this swarm, run the following command:
docker swarm join \
--tokenSWMTKN-1-37fe5tarzcy50mazbe1e3ewyblkfk7xf9kx9ncanz0wx3q70e1-a7wn9tiepd114if6smuiqlez3\
192.168.63.217:2377
[root@master wordpress]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
e9naz0ctzaaer4bwleruo34x6 master Ready Active Leader
rfcbavxd8yrixximm9e1i6dsn node1 Ready Active
shrzku0k3xx87526lkkkyrxsi node2 Ready Active
[root@masterwordpress]# docker service create --mount type=bind,source=/web/,target=/web/--network nginx_network --name php -p 9000:9000192.168.63.217:5000/lnmp/php:1.0
[root@masterwordpress]# docker service ls
ID NAME MODE REPLICAS IMAGE
ira3ezabroai php replicated 1/1 192.168.63.217:5000/lnmp/php:1.0
10、启动nginx service:
[root@masterwordpress]#docker service create --mount type=bind,source=/web/,target=/web/ --network nginx_network --name web -p 80:80 192.168.63.217:5000/lnmp/nginx:1.0
[root@master wordpress]# docker servicescale web=2
web scaled to 2
13、看一下我们的容器到底运行在哪个linux主机上呢:
[root@master wordpress]# docker service ls
ID NAME MODE REPLICAS IMAGE
ira3ezabroai php replicated 1/1 192.168.63.217:5000/lnmp/php:1.0
kcxqzxwe0dzb mysql replicated 1/1 192.168.63.217:5000/lnmp/mysql:1.0
ufn1n5phtsqn web replicated 2/2 192.168.63.217:5000/lnmp/nginx:1.0
#####
[root@master wordpress]# docker service ps php
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
ptxokpvq1b7s php.1 192.168.63.217:5000/lnmp/php:1.0 master Running Running 5 minutes ago
[root@master wordpress]# docker service ps mysql
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
zowbxqnr9toi mysql.1 192.168.63.217:5000/lnmp/mysql:1.0 node2 Running Running 2 minutes ago
[root@master wordpress]# docker service ps web
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
vhk44hij7gnu web.1 192.168.63.217:5000/lnmp/nginx:1.0 node1 Running Running 3 minutes ago
u1vdnr0ujzl7 web.2 192.168.63.217:5000/lnmp/nginx:1.0 node2 Running Running about a minute ago
[root@master web]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
e9naz0ctzaaer4bwleruo34x6 master Ready Active Leader
rfcbavxd8yrixximm9e1i6dsn node1 Down Active
shrzku0k3xx87526lkkkyrxsi node2 Ready Active
[root@master web]# docker service ps php
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
ptxokpvq1b7s php.1 192.168.63.217:5000/lnmp/php:1.0 master Running Running 18 minutes ago
[root@master web]# docker service ps mysql
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
zowbxqnr9toi mysql.1 192.168.63.217:5000/lnmp/mysql:1.0 node2 Running Running 15 minutes ago
[root@master web]# docker service ps web
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
jqcuqzjdgi9y web.1 192.168.63.217:5000/lnmp/nginx:1.0 master Running Running 2 minutes ago
vhk44hij7gnu \_web.1 192.168.63.217:5000/lnmp/nginx:1.0 node1 Shutdown Running 2 minutes ago
u1vdnr0ujzl7 web.2 192.168.63.217:5000/lnmp/nginx:1.0 node2 Running Running 14 minutes ago