Docker部署应用

以部署投票应用example-voting-app为例

在管理节点获取docker-stack.yml

在宿主机:

1
$ docker-machine scp example-voting-app/docker-stack.yml manager:/home/docker/

或在虚拟机:

1
2
$ git clone https://github.com/docker/example-voting-app.git
$ cp example-voting-app/docker-stack.yml ./

部署应用

(1)在管理节点部署应用

1
docker stack deploy --compose-file docker-stack.yml <APP-NAME>
1
2
3
4
5
6
7
$ docker stack deploy --compose-file docker-stack.yml vote
Updating service vote_result (id: pe1l8kycwvzdkffnpyw0ch4sx)
Updating service vote_worker (id: tigz3d6ij4t3g083vf6rea6kj)
Updating service vote_visualizer (id: buqqz43gkbo91nrhfc7edyiga)
Updating service vote_redis (id: kt8gx6bwrqai4i0xcymimo8vu)
Updating service vote_db (id: bl7lptuacc5ul5lebjl37z71f)
Updating service vote_vote (id: d2eqrkqtjlbtvkx3iq8xbw132)

(2)验证应用已部署

1
docker stack services <APP-NAME>
1
2
3
4
5
6
7
8
$ docker stack services vote
ID NAME MODE REPLICAS IMAGE
bl7lptuacc5u vote_db replicated 1/1 postgres:9.4
buqqz43gkbo9 vote_visualizer replicated 1/1 dockersamples/visualizer:stable
d2eqrkqtjlbt vote_vote replicated 1/2 dockersamples/examplevotingapp_vote:before
kt8gx6bwrqai vote_redis replicated 2/2 redis:alpine
pe1l8kycwvzd vote_result replicated 0/1 dockersamples/examplevotingapp_result:before
tigz3d6ij4t3 vote_worker replicated 1/1 dockersamples/examplevotingapp_worker:latest

查看应用效果

现在我们部署的投票应用已经启动,我们可以为猫和狗进行投票,查看投票结果,并且监控管理和工作节点、容器以及服务。

投票页面:<MANAGER-IP>:5000

1
http://192.168.99.101:5000/

结果页面:<MANAGER-IP>:5001

1
http://192.168.99.101:5001/

使用visualizer监控APP:<MANAGER-IP>:8080

1
http://192.168.99.101:8080/

应用操作

(1)停止App

1
2
3
> docker-machine ls
> docker-machine stop worker
> docker-machine stop manager

(2)启动App

1
2
3
4
5
> docker-machine ls
> docker-machine start manager
> docker-machine start worker
> docker-machine ssh manager
> docker stack services vote

(3)移除App

1
2
3
$ docker stack rm vote
$ docker stack services vote //确认vote应用已被移除
$ docker node ls //确认集群仍然在节点中运行

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :