Docker swarm 实战-部署wordpress

Docker swarm 实战-部署wordpress

创建一个overlay的网络

docker network create -d overlay demo

6imq8da3vcwvj2n499k4bwdlt
docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
feea5ba8507b        bridge              bridge              local
6imq8da3vcwv        demo                overlay             swarm
84e129614ea7        docker_gwbridge     bridge              local
d1b0002bf8c8        host                host                local
dgfigrlal70j        ingress             overlay             swarm
633e169e521c        none                null                local

在swarm集群中,创建一个网络之后并不会立即同步到其他节点中,只有当该网络被某个服务使用时,才会同步过去。

创建一个mysql服务

docker service create --name mysql --env MYSQL_ROOT_PASSWORD=root --env MYSQLDATABASE=wordpress --network=demo --mount type=volume,source=mysql-data,destination=/var/lib/mysql mysql:5.7

ep1vpcjhsevqk6s8qti0m3voc
overall progress: 1 out of 1 tasks
1/1: running   [==================================================>]
verify: Service converged
docker service ls

ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
ep1vpcjhsevq        mysql               replicated          1/1                 mysql:5.7
docker service ps mysql
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE           ERROR               PORTS
rzl03fvgyjkv        mysql.1             mysql:latest        swarm-manager       Running             Running 2 minutes ago
docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
34aae70f6c30        mysql:5.7        "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        3306/tcp            mysql.1.rzl03fvgyjkvruwfcylsprwub

创建一个wordpress服务

docker service create --name wordpress -p 80:80 --network=demo --env WORDPRESS_DB_PASSWORD=root --env WORDPRESS+DB_HOST=mysql wordpress

7w40cbn1clnd3i5zxaweyf726
overall progress: 1 out of 1 tasks
1/1: running   [==================================================>]
verify: Service converged
docker service ls

ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
ep1vpcjhsevq        mysql               replicated          1/1                 mysql:latest
7w40cbn1clnd        wordpress           replicated          1/1                 wordpress:latest    *:80->80/tcp
docker service ps wordpress

ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE           ERROR                       PORTS
yknadxszq302        wordpress.1         wordpress:latest    swarm-worker1       Running             Running 6 seconds ago

浏览器访问

wordpress.png

posted @ 2019-01-16 21:21  StaryJie  阅读(778)  评论(0编辑  收藏  举报