Docker compose v3版本构建跨主机容器编排构建wordpress集群
在Docker 1.13版本之后,可以说Docker 对于compose容器调度编排实现了飞跃,可以使得在编排容器的时候可以结合Docker swarm集群和跨主机通讯的概念。在Docker swarm 的基础之上引入stack对service镜像管理和编排。下面我们实战一下用之前构建wordpress集群来测试一下:环境要求:1、存在了Docker swarm集群:# docker node ls
ID HOSTNAMESTATUSAVAILABILITYMANAGER STATUS
e9naz0ctzaaer4bwleruo34x6 *master Ready Active Reachable
rfcbavxd8yrixximm9e1i6dsn node1 Ready Active Leader
shrzku0k3xx87526lkkkyrxsi node2 Ready Active Reachable##我这里有三个集群节点,都是以manager的形式存在,当然容器调度也是不影响的。
2、Docker 版本要求是1.13以上的版本:# docker version
Client:
Version: 17.04.0-ce
API version:1.28
Go version: go1.7.5
Git commit: 4845c56
Built: Mon Apr3 18:01:50 2017
OS/Arch: linux/amd64
Server:
Version: 17.04.0-ce
API version:1.28 (minimum version 1.12)
Go version: go1.7.5
Git commit: 4845c56
Built: Mon Apr3 18:01:50 2017
OS/Arch: linux/amd64
Experimental: false3、基于之前的镜像我们构建时候非常简单,直接编写compose文件即可:# cat compose_wordpress.yml
version: '3'
services:
php:
p_w_picpath:192.168.63.217:5000/lnmp/php:1.0
volumes:
-/web:/web
ports:
- 9000:9000
nginx:
p_w_picpath:192.168.63.217:5000/lnmp/nginx:1.0
ports:
- 80:80
volumes:
- /web:/web
depends_on:
- mysql
deploy:
replicas: 3
restart_policy:
condition: on-failure mysql:
p_w_picpath:192.168.63.217:5000/lnmp/nginx:1.0
ports:
- 3306:3306
volumes:
- /data:/var/lib/mysql ##注释;restrat_policy:表示重启条件,我们定义是错误重启。在v3版本,没有了link这个概念,容器之间通讯都是使用overlay网络。通讯名称都是以服务名称互联。
4、开始构建:# docker stack deploy -c compose_wordpress.yml wordpress
Creating network wordpress_default
Creating service wordpress_php
Creating service wordpress_nginx
Creating service wordpress_mysql构建时候可以看到创建一个wordpress_default这样一个overlay网络:
# docker network ls
NETWORK ID NAME DRIVER SCOPE
e1608d2e6f7d bridge bridge local
5de3863d8bf9 docker_gwbridge bridge local
c97de54d6fcc dockercompose_default bridge local
080a6647873b host host local
wdqd0cye6t5h wordpress_default overlay swarm
5、我们查看一下相关的stack状态:# docker stack services wordpress
ID NAME MODE REPLICAS IMAGE
hx5zabzybbny wordpress_php replicated 1/1 192.168.63.217:5000/lnmp/php:1.0
me5s3v37tzsw wordpress_nginx replicated 3/3 192.168.63.217:5000/lnmp/nginx:1.0
txz5xzgnkjbc wordpress_mysql replicated 1/1 192.168.63.217:5000/lnmp/nginx:1.06、可以看到worepress 这个调度的stack已经起起来了,因为是与Docker swarm结合,所以我们也可以用Docker swarm 形式来查看和管理:# docker service ls
ID NAME MODE REPLICAS IMAGE
hx5zabzybbny wordpress_php replicated 1/1 192.168.63.217:5000/lnmp/php:1.0
me5s3v37tzsw wordpress_nginx replicated 3/3 192.168.63.217:5000/lnmp/nginx:1.0
txz5xzgnkjbc wordpress_mysql replicated 1/1 192.168.63.217:5000/lnmp/nginx:1.0
# docker service ps wordpress_nginx
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
9pcbe6zvjoa5 wordpress_nginx.1 192.168.63.217:5000/lnmp/nginx:1.0 master Running Running 4 minutes ago
ode397gc036g wordpress_nginx.2 192.168.63.217:5000/lnmp/nginx:1.0 node2 Running Running 4 minutes ago
76tznesy3bm8 wordpress_nginx.3 192.168.63.217:5000/lnmp/nginx:1.0 node1 Running Running 4 minutes ago
7、都起起来了,我们访问一下web界面看一下服务是否正常:
到处已经完成了这个管理,我们可以看到Docker 社区的集群软件在不断的成熟和完善,期待Docker 推出更好更实用的功能。 Docker详情与集群架构部分可以查看:http://www.roncoo.com/course/view/3e9d9c48f76f4c698b8349d04b763467
页:
[1]