下面給大家介紹在swarm集群里通過(guò)service部署wordpress,希望對(duì)需要的朋友有所幫助!
創(chuàng)建一個(gè)overlay驅(qū)動(dòng)的網(wǎng)絡(luò)
docker network create -d overlay wordpress [vagrant@swarm-manager ~]$ docker network ls NETWORK ID NAME DRIVER SCOPE q3rp3i79eud7 wordpress overlay swarm
創(chuàng)建mysql容器
docker service create --name mysql --env MYSQL_ROOT_PASSWORD=root --env MYSQL_DATABASE=wordpress --network wordpress --mount type=volume,source=mysql-data,destination=/var/lib/mysql mysql
創(chuàng)建wordpress
docker service create --name wordpress -p 80:80 --env WORDPRESS_DB_PASSWORD=root --env WORDPRESS_DB_HOST=mysql --network wordpress wordpress
查看節(jié)點(diǎn)分布
# 服務(wù)列表 [vagrant@swarm-manager ~]$ docker service ls ID NAME MODE REPLICAS IMAGE PORTS vxz0bfmul9th mysql replicated 1/1 mysql:5.7.22 cpe3wqrsoqxi wordpress replicated 1/1 wordpress:latest *:80->80/tcp # wordpress服務(wù)的節(jié)點(diǎn)分布 [vagrant@swarm-manager ~]$ docker service ps wordpress ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS tnh4f0ldyidl wordpress.1 wordpress:latest swarm-manager Running Running 4 minutes ago # mysql服務(wù)的節(jié)點(diǎn)分布 [vagrant@swarm-manager ~]$ docker service ps mysql ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS jns8bllzbz94 mysql.1 mysql:5.7.22 swarm-work1 Running Running 33 minutes ago
雖然 wordpress 只分布在了swarm-manager(192.168.205.10)這一個(gè)節(jié)點(diǎn)上,但是我們發(fā)現(xiàn)使用如下鏈接訪問(wèn),效果都是一樣的,是不是很神奇。。。具體原因詳見(jiàn)7.6
http://192.168.205.10/ http://192.168.205.11/ http://192.168.205.12/