在Docker 1.13版本以後,能夠說Docker 對於compose容器調度編排實現了飛躍,可使得在編排容器的時候能夠結合Docker swarm集羣和跨主機通信的概念。在Docker swarm 的基礎之上引入stack對service鏡像管理和編排。下面咱們實戰一下用以前構建wordpress集羣來測試一下:php
環境要求:node
一、存在了Docker swarm集羣:mysql
[root@master ~]# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS e9naz0ctzaaer4bwleruo34x6 * master Ready Active Reachable rfcbavxd8yrixximm9e1i6dsn node1 Ready Active Leader shrzku0k3xx87526lkkkyrxsi node2 Ready Active Reachable
##我這裏有三個集羣節點,都是以manager的形式存在,固然容器調度也是不影響的。linux
二、Docker 版本要求是1.13以上的版本:nginx
[root@master ~]# docker version Client: Version: 17.04.0-ce API version: 1.28 Go version: go1.7.5 Git commit: 4845c56 Built: Mon Apr 3 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 Apr 3 18:01:50 2017 OS/Arch: linux/amd64 Experimental: false
三、基於以前的鏡像咱們構建時候很是簡單,直接編寫compose文件便可:web
[root@master stack]# 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
##註釋;sql
restrat_policy:表示重啓條件,咱們定義是錯誤重啓。docker
在v3版本,沒有了link這個概念,容器之間通信都是使用overlay網絡。通信名稱都是以服務名稱互聯。bash
四、開始構建:網絡
[root@master stack]# 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網絡: [root@master stack]# 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
五、咱們查看一下相關的stack狀態:
[root@master 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.0
六、能夠看到worepress 這個調度的stack已經起起來了,由於是與Docker swarm結合,因此咱們也能夠用Docker swarm 形式來查看和管理:
[root@master stack]# 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 [root@master stack]# 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
七、都起起來了,咱們訪問一下web界面看一下服務是否正常:
處處已經完成了這個管理,咱們能夠看到Docker 社區的集羣軟件在不斷的成熟和完善,期待Docker 推出更好更實用的功能。
Docker詳情與集羣架構部分能夠查看:http://www.roncoo.com/course/view/3e9d9c48f76f4c698b8349d04b763467