Chapter7-DockerSwarm创建mysql5.7+wordpress5.2.4服务
# 查看docker版本
[vagrant@docker-node1 ~]$ docker --version
Docker version 19.03.2, build 6a30dfc
# 创建overlay网络
[vagrant@docker-node1 ~]$ docker network ls
NETWORK ID NAME DRIVER SCOPE
cdc57909fafa bridge bridge local
d297fe97df61 docker_gwbridge bridge local
da4e716bb141 host host local
50wvtx3dsp0s ingress overlay swarm
592d9192c312 none null local
[vagrant@docker-node1 ~]$ docker network create -d overlay
demo
5rvasl8x3wpisze03ktr4b4yp
[vagrant@docker-node1 ~]$ docker network ls
NETWORK ID NAME DRIVER SCOPE
cdc57909fafa bridge bridge local
5rvasl8x3wpi demo overlay swarm
d297fe97df61 docker_gwbridge bridge local
da4e716bb141 host host local
50wvtx3dsp0s ingress overlay swarm
592d9192c312 none null local
[vagrant@docker-node2 ~]$ docker network ls
NETWORK ID NAME DRIVER SCOPE
ae68202eab49 bridge bridge local
0031b9800dfb docker_gwbridge bridge local
a2be883ab5c0 host host local
50wvtx3dsp0s ingress overlay swarm
1c00e2efaeab none null local
[vagrant@docker-node3 ~]$ docker network ls
NETWORK ID NAME DRIVER SCOPE
a0a55c58febf bridge bridge local
6658a03e2ca5 docker_gwbridge bridge local
f02845cbffb4 host host local
50wvtx3dsp0s ingress overlay swarm
956a2612c91a none null local
[vagrant@docker-node1 ~]$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
sylor9527/worker 1.0 c14828c8e056 3 months
ago 679MB
sylor9527/result-app 1.0 d9e52da914bd 3 months
ago 908MB
sylor9527/voting-app 1.0 c02c1e6c3c77 3 months
ago 893MB
python 2.7-alpine 780ede8fb4a7 4 months
ago 61.7MB
node 13.0.1 4ac0e1872789 4 months
ago 933MB
tomcat 7.0 e3a393545a10 4 months
ago 506MB
tomcat 8.5.47 882487b8be1d 4 months
ago 507MB
ubuntu 16.04 b9409899fe86 4 months
ago 122MB
ubuntu 18.04 cf0f3ca922e0 4 months
ago 64.2MB
wordpress 5.2.4 264da8cf7ba4 4 months
ago 537MB
node 8.16.2 52a261fa5e4b 4 months
ago 895MB
sylor9527/flask-skeleton 1.0 01ebde376b3e 4 months
ago 920MB
sylor9527/my-nginx 1.0 589c7ae397f9 4 months
ago 126MB
sylor9527/flask-redis 1.0 f7187b115207 4 months
ago 891MB
centos 8.0.1905 0f3e07c0138f 5 months
ago 220MB
redis 5.0.6 01a52b3b5cd1 5 months
ago 98.2MB
nginx 1.17.4 f949e7d76d63 5 months
ago 126MB
python 2.7 b707c2244b7d 5 months
ago 886MB
mysql 5.7 383867b75fd2 5 months
ago 373MB
busybox 1.31.0 19485c79a9bb 5 months
ago 1.22MB
postgres 9.4 8854ac6fdc43 9 months
ago 225MB
centos 6.9 2199b8eb8390 11 months
ago 195MB
centos 7.5.1804 cf49811e3cdb 11 months
ago 200MB
mysql 5.6.40 50328380b2b4 19 months
ago 256MB
jwilder/whoami 1.0 89be8564e650 22 months
ago 10.1MB
dockercloud/haproxy 1.6.7 3199480a6120 2 years ago 42.5MB
ubuntu 12.04 5b117edd0b76 2 years ago 104MB
java 8 d23bdf5b1b1b 3 years
ago 643MB
java 7 5dc48a6b75af 3 years
ago 584MB
[vagrant@docker-node2 ~]$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
sylor9527/whoami 1.0 1e0a0d5c9e58 3 months
ago 13MB
golang alpine3.10 3024b4e742b0 4 months
ago 359MB
alpine 3.10 965ea09ff2eb 4 months
ago 5.55MB
tomcat 7.0 e3a393545a10 4 months
ago 506MB
ubuntu 16.04 b9409899fe86 4 months
ago 122MB
ubuntu 18.04 cf0f3ca922e0 4 months
ago 64.2MB
wordpress 5.2.4 264da8cf7ba4 4 months
ago 537MB
postgres 9.4 36726735dc3c 4 months
ago 206MB
sylor9527/flask-redis 1.0 2c510b94a1fd 4 months
ago 891MB
centos 8.0.1905 0f3e07c0138f 5 months
ago 220MB
python 2.7 b707c2244b7d 5 months
ago 886MB
mysql 5.7 383867b75fd2 5 months
ago 373MB
busybox 1.31.0 19485c79a9bb 5 months
ago 1.22MB
centos 6.9 2199b8eb8390 11 months
ago 195MB
centos 7.5.1804 cf49811e3cdb 11 months
ago 200MB
mysql 5.6.40 50328380b2b4 19 months
ago 256MB
jwilder/whoami 1.0 89be8564e650 22 months
ago 10.1MB
java 7 5dc48a6b75af 3 years
ago 584MB
[vagrant@docker-node3 ~]$ docker image ls
REPOSITORY TAG IMAGE
ID CREATED SIZE
wordpress 5.2.4 264da8cf7ba4 4 months
ago 537MB
mysql 5.7 383867b75fd2 5 months
ago 373MB
busybox 1.31.0 19485c79a9bb 5 months
ago 1.22MB
jwilder/whoami 1.0 89be8564e650 22 months
ago 10.1MB
# 创建mysql服务
[vagrant@docker-node1 ~]$ 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
mysql:5.7
6l2hoyni40l7m6259zndyx8df
overall progress: 1 out of 1 tasks
1/1: running [==================================================>]
verify: Service converged
# 验证服务
[vagrant@docker-node1 ~]$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
6l2hoyni40l7 mysql replicated 1/1 mysql:5.7
[vagrant@docker-node1 ~]$ docker service ps mysql
ID NAME IMAGE NODE DESIRED
STATE CURRENT STATE ERROR PORTS
nyfqahn48pig mysql.1 mysql:5.7 docker-node1 Running Running 5
minutes ago
[vagrant@docker-node1 ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
26b32cfb8074 mysql:5.7 "docker-entrypoint.s…" 9 minutes ago Up 9
minutes 3306/tcp, 33060/tcp mysql.1.nyfqahn48pigcclnu7apm6mck
# 创建wordpress服务
[vagrant@docker-node1 ~]$ docker service create --name
wordpress -p 80:80 --env WORDPRESS_DB_PASSWORD=root --env
WORDPRESS_DB_HOST=mysql --network demo wordpress:5.2.4
image wordpress:5.2.4 could not be accessed on a registry to
record
its digest. Each node will access wordpress:5.2.4
independently,
possibly leading to different nodes running different
versions of the image.
vup3ytqm31pes4pp0giqvfnqf
overall progress: 1 out of 1 tasks
1/1: running [==================================================>]
verify: Service converged
# 验证服务
[vagrant@docker-node1 ~]$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
6l2hoyni40l7 mysql replicated 1/1 mysql:5.7
ibrnwuodlmja wordpress replicated 1/1 wordpress:5.0.24 *:80->80/tcp
[vagrant@docker-node1 ~]$ docker service ps wordpress
ID NAME IMAGE NODE DESIRED
STATE CURRENT STATE ERROR PORTS
qlmdl4v2tkmi wordpress.1 wordpress:5.0.24 docker-node2 Running Running about a minute ago
[vagrant@docker-node1 ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
26b32cfb8074 mysql:5.7 "docker-entrypoint.s…" 11 minutes ago Up 11
minutes 3306/tcp, 33060/tcp mysql.1.nyfqahn48pigcclnu7apm6mck
[vagrant@docker-node2 ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a14ebfd992cd wordpress:5.0.24 "docker-entrypoint.s…" 2
minutes ago Up 2 minutes 80/tcp wordpress.1.qlmdl4v2tkmiwv8nc0juhpl58
# 验证结果,通过浏览器访问
http://192.168.205.12
http://192.168.205.10
http://192.168.205.11
[vagrant@docker-node2 ~]$ docker network ls
NETWORK ID NAME DRIVER SCOPE
ae68202eab49 bridge bridge local
5rvasl8x3wpi demo overlay swarm
0031b9800dfb docker_gwbridge bridge local
a2be883ab5c0 host host local
50wvtx3dsp0s ingress overlay swarm
1c00e2efaeab none null local
!!The End!!