learning docker steps(5) ----- docker stack 初次体验

参考:https://docs.docker.com/get-started/part5/

stack 技术栈。技术栈是一组相关的服务,它们共享依赖项并且可以一起进行编排和扩展。单个技术栈能够定义和协调整个应用的功能(虽然很复杂的应用程序可能需要使用多个技术栈)。

按我的理解就是docker的最终的目标是为了提供服务:比如我们访问网站,计算网站被请求访问次数也是需求,要实现需求的话,就需要提供相关的服务,用什么实现呢,就是docker stack来实现。

在今后的学习当中我们如何学习到k8s的话,可以把它理解成k8s的pod概念。

 

如下是实践操作,按照参考的yaml有点小问题,稍微修改了一下:

root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker-machine ssh myvm1 “docker swarm init –advertise-addr 192.168.99.100:2377”
Swarm initialized: current node (qmsgq8wgya34mfxgd94jvt2hh) is now a manager.

To add a worker to this swarm, run the following command:

docker swarm join –token SWMTKN-1-0l4021umvvtfjk9meufz4gks5gc8qa5yu16leg367m9s3ca24e-cwuj8c047v6xvvbxho2flx6xw 192.168.99.100:2377

To add a manager to this swarm, run ‘docker swarm join-token manager’ and follow the instructions.

root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker-machine ssh myvm2 “docker swarm join –token SWMTKN-1-0l4021umvvtfjk9meufz4gks5gc8qa5yu16leg367m9s3ca24e-cwuj8c047v6xvvbxho2flx6xw 192.168.99.100:2377”
This node joined a swarm as a worker.
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker-machine ssh myvm1
## .
## ## ## ==
## ## ## ## ## ===
/”””””””””””””””””\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\_______/
_ _ ____ _ _
| |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __
| ‘_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ ‘__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 18.06.1-ce, build HEAD : c7e5c3e – Wed Aug 22 16:27:42 UTC 2018
Docker version 18.06.1-ce, build e68fc7a
docker@myvm1:~$ docker stack deploy -c docker-compose.yml getstartedlab
services.visualizer.deploy.placement must be a mapping
docker@myvm1:~$ docker stack deploy -c docker-compose.yml getstartedlab
services.visualizer.deploy.placement must be a mapping
docker@myvm1:~$ exit
exit status 1

通过去掉 解决该问题:
deploy:
placement:
constraints:[node.role == manager]
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker-machine ssh myvm1
## .
## ## ## ==
## ## ## ## ## ===
/”””””””””””””””””\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\_______/
_ _ ____ _ _
| |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __
| ‘_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ ‘__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 18.06.1-ce, build HEAD : c7e5c3e – Wed Aug 22 16:27:42 UTC 2018
Docker version 18.06.1-ce, build e68fc7a

docker@myvm1:~$ docker stack deploy -c docker-compose.yml getstartedlab
Creating network getstartedlab_webnet
Creating service getstartedlab_web

Creating service getstartedlab_visualizer
docker@myvm1:~$ exit

root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
myvm1 * virtualbox Running tcp://192.168.99.100:2376 v18.06.1-ce
myvm2 – virtualbox Running tcp://192.168.99.101:2376 v18.06.1-ce

在页面http://192.168.99.101:8080/
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker-machine ssh myvm1 “docker stack ps getstartedlab”
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
yhauhypkguok getstartedlab_visualizer.1 dockersamples/visualizer:stable myvm1 Running Running 6 minutes ago
lo65xbvsmyfb getstartedlab_web.1 pan19881018/get-start:part2 myvm1 Running Running 7 minutes ago
m7fompj28ptg getstartedlab_web.2 pan19881018/get-start:part2 myvm2 Running Running 7 minutes ago
y1i1bghzyhuc getstartedlab_web.3 pan19881018/get-start:part2 myvm2 Running Running 7 minutes ago
mej5094xv5k6 getstartedlab_web.4 pan19881018/get-start:part2 myvm1 Running Running 7 minutes ago
z55f2hdwwyzc getstartedlab_web.5 pan19881018/get-start:part2 myvm2 Running Running 7 minutes ago

 

如下图所示:我们就把stack的样例实现了:

 

posted @ 2018-12-25 16:34  嵌入式实操  阅读(450)  评论(0编辑  收藏  举报