教程栏目给大家介绍在swarm集群里通过service部署wordpress,希望对需要的朋友有所帮助!
创建一个overlay驱动的网络
1
2
3
4
docker network create -d overlay wordpress
[vagrant@swarm-manager ~]$ docker network ls
NETWORK ID NAME DRIVER SCOPE
q3rp3i79eud7 wordpress overlay swarm
创建mysql容器
1
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
创建wordpress
1
docker service create --name wordpress -p 80:80 --env WORDPRESS_DB_PASSWORD=root --env WORDPRESS_DB_HOST=mysql --network wordpress wordpress
查看节点分布
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 服务列表
[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服务的节点分布
[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服务的节点分布
[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)这一个节点上,但是我们发现使用如下链接访问,效果都是一样的,是不是很神奇。。。具体原因详见7.6
1
2
3
http://192.168.205.10/
http://192.168.205.11/
http://192.168.205.12/
以上就是怎么在swarm集群里通过service部署wordpress的详细内容,更多请关注php中文网其它相关文章!