实验环境:
三台阿里云服务器
master:59.110.224.16 iZ2zebnlswk1d44x5zohfoZ
worker1:47.94.164.5 iZ2ze5ys0umutubelpncwsZ
worker2:47.104.105.70 iZm5e8mciwctrh1zj1f7r3Z
操作系统 centos ,3306端口已开,8089端口已开
步骤:
1.docker network create -d overlay demo
2.docker service create --name mysql --env MYSQL_ROOT_PASSWORD=root --env MYSQL_DATABASE=wordpress --network demo --mount type=volume,source=mysql-data,destination=/var/lib/mysql -p 3306:3306 mysql:5.7
mysql 服务此时被安装在47.104.105.70上
3.docker service create --name wordpress -p 8089:80 --env WORDPRESS_DB_PASSWORD=root --env WORDPRESS_DB_HOST=47.104.105.70:3306 --network demo wordpress
现象:
1.在创建mysql service时,我必须要-p 3306:3306 才能让wordpress服务访问到
2.在创建wordpress service时,我必须要写明WORDPRESS_DB_HOST=47.104.105.70:3306,也就是指定mysql所在的IP以及端口号3306
只有这样写我才能打开wordpress,但是虽然可以打开但是其他节点缺无法访问到
docker service ls 结果如下:
yqtfn4z75ai3 mysql replicated 1/1 mysql:5.7 *:3306->3306/tcp
ymkaere3fnml wordpress replicated 1/1 wordpress:latest *:8089->80/tcp
master->docker network ls ->存在demo的overlay
worker1->docker network ls ->不存在demo的overlay
worker2->docker network ls ->存在demo的overlay
[root@iZ2zebnlswk1d44x5zohfoZ ~]# docker service logs wordpress
wordpress.1.quo67ighyp3n@iZ2zebnlswk1d44x5zohfoZ | WordPress not found in /var/www/html - copying now...
wordpress.1.quo67ighyp3n@iZ2zebnlswk1d44x5zohfoZ | Complete! WordPress has been successfully copied to /var/www/html
wordpress.1.quo67ighyp3n@iZ2zebnlswk1d44x5zohfoZ | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.0.13. Set the 'ServerName' directive globally to suppress this message
wordpress.1.quo67ighyp3n@iZ2zebnlswk1d44x5zohfoZ | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.0.13. Set the 'ServerName' directive globally to suppress this message
wordpress.1.quo67ighyp3n@iZ2zebnlswk1d44x5zohfoZ | [Mon May 07 10:17:31.562835 2018] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.25 (Debian) PHP/7.2.5 configured -- resuming normal operations
wordpress.1.quo67ighyp3n@iZ2zebnlswk1d44x5zohfoZ | [Mon May 07 10:17:31.562890 2018] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
wordpress.1.quo67ighyp3n@iZ2zebnlswk1d44x5zohfoZ | 10.255.0.2 - - [07/May/2018:10:17:45 +0000] "GET / HTTP/1.1" 200 18718 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"
wordpress.1.quo67ighyp3n@iZ2zebnlswk1d44x5zohfoZ | 10.255.0.2 - - [07/May/2018:10:17:46 +0000] "GET /favicon.ico HTTP/1.1" 200 227 "http://59.110.224.16:8089/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"
访问:59.110.224.16:8089
访问其他IP都不行