learning docker steps(3) ----- docker services 初次体验
参考:https://docs.docker.com/get-started/part3/#docker-composeyml
docker 的 service样例, 我们可以理解成是一个本地负载均衡的样例,一次性创建5个容器,处理请求http请求,并返回处理请求的主机。
1. docker swarm 服务初始化: 进入集群模式
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker swarm init
Swarm initialized: current node (oyunvuhucng5600g5xve3tiad) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join –token SWMTKN-1-2j08q2027t3vkazrqg8btessvub0rdjh7nwswqeysmljt1st3n-drqgpun6zvla7ok7d7jhk8see 192.168.0.119:2377
To add a manager to this swarm, run ‘docker swarm join-token manager’ and follow the instructions.
2. docker stack deploy 集群启动,通过-c指定文件,getstartedlab为名称
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker stack deploy -c docker-compose.yml getstartedlab
Creating network getstartedlab_webnet
Creating service getstartedlab_web
3. 查看当前的服务
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
snqp0guylvnq getstartedlab_web replicated 5/5 pan19881018/get-start:part2 *:4000->80/tcp
4. 查看服务内的容器
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker service ps getstartedlab_web
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
3h3qhz5zdl4l getstartedlab_web.1 pan19881018/get-start:part2 vmuser-virtual-machine Running Running about a minute ago
xym5mer3ymx3 getstartedlab_web.2 pan19881018/get-start:part2 vmuser-virtual-machine Running Running about a minute ago
t3i3ntoy5mke getstartedlab_web.3 pan19881018/get-start:part2 vmuser-virtual-machine Running Running about a minute ago
7wvii3mug6gm getstartedlab_web.4 pan19881018/get-start:part2 vmuser-virtual-machine Running Running about a minute ago
yq7die0874vz getstartedlab_web.5 pan19881018/get-start:part2 vmuser-virtual-machine Running Running about a minute ago
5 查看当前的容器
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker container ls -q
a7e47e7cfaa0
85ed544aa172
af09c78bc902
9002394e8581
6fbc188a3e5a
6. 测试负载均衡,可以发现我们每次的请求,后台返回的主机名称是不一样的,从而实现负载均衡。
vmuser@vmuser-virtual-machine:~$ curl http://localhost:4888
<h3>Hello World!</h3><b>Hostname:</b> 4464de9fd6ee<br/><b>Visits:</b> <i>cannot connect to Redis, counter disablvmuser@vmuser-virtual-machine:~$ curl 4 http://localhost:4000
curl: (7) Couldn’t connect to server
<h3>Hello World!</h3><b>Hostname:</b> af09c78bc902<br/><b>Visits:</b> <i>cannot connect to Redis, counter disabled</i>vmuser@vmuser-virtual-machine:~$ curl 4 http://localhost:4000
curl: (7) Couldn’t connect to server
<h3>Hello World!</h3><b>Hostname:</b> 9002394e8581<br/><b>Visits:</b> <i>cannot connect to Redis, counter disabled</i>vmuser@vmuser-virtual-machine:~$ curl 4 http://localhost:4000
curl: (7) Couldn’t connect to server
<h3>Hello World!</h3><b>Hostname:</b> a7e47e7cfaa0<br/><b>Visits:</b> <i>cannot connect to Redis, counter disabled</i>vmuser@vmuser-virtual-machine:~$ curl 4 http://localhost:4000
curl: (7) Couldn’t connect to server
<h3>Hello World!</h3><b>Hostname:</b> 6fbc188a3e5a<br/><b>Visits:</b> <i>cannot connect to Redis, counter disabled</i>vmuser@vmuser-virtual-machine:~$ curl 4 http://localhost:4000
curl: (7) Couldn’t connect to server
<h3>Hello World!</h3><b>Hostname:</b> 85ed544aa172<br/><b>Visits:</b> <i>cannot connect to Redis, counter disabled</i>vmuser@vmuser-virtual-machine:~$ curl 4 http://localhost:4000
curl: (7) Couldn’t connect to server
<h3>Hello World!</h3><b>Hostname:</b> af09c78bc902<br/><b>Visits:</b> <i>cannot connect to Redis, counter disabled</i>vmuser@vmuser-virtual-machine:~$ curl 4 http://localhost:4000
curl: (7) Couldn’t connect to server
<h3>Hello World!</h3><b>Hostname:</b> 9002394e8581<br/><b>Visits:</b> <i>cannot connect to Redis, counter disabled</i>vmuser@vmuser-virtual-machine:~$ curl 4 http://localhost:4000
curl: (7) Couldn’t connect to server
<h3>Hello World!</h3><b>Hostname:</b> a7e47e7cfaa0<br/><b>Visits:</b> <i>cannot connect to Redis, counter disablvmuser@vmuser-virtual-machine:~$
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker container ls -q
a7e47e7cfaa0
85ed544aa172
af09c78bc902
9002394e8581
6fbc188a3e5a
7. 删除服务
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker stack rm getstartedlab
Removing service getstartedlab_web
Removing network getstartedlab_webnet
8. 强制离开服务,退出集群模式
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker swarm leave –force
Node left the swarm.
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker container ls -q
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker service ls
Error response from daemon: This node is not a swarm manager. Use “docker swarm init” or “docker swarm join” to connect this node to swarm and try again.
learning docker steps(3) ----- docker services 初次体验的更多相关文章
- learning docker steps(8) ----- docker network 初次体验
参考: docker network 主要是介绍了docker 容器之间的组网模式, 一般来说实像组网主要是依赖于bridge iptalbes vlan来实现,但是附带的如端口转发会降低效率. 新型 ...
- learning docker steps(2) ----- docker contailner 初次体验
参考:https://docs.docker-cn.com/get-started/part2/ Dockerfile的内容如下所示: # 将官方 Python 运行时用作父镜像 FROM pytho ...
- learning docker steps(1) ----- docker 安装
docker 安装 参考:https://docs.docker.com/install/linux/docker-ce/ubuntu/ 按如下指令可安装: $ sudo apt-get instal ...
- learning docker steps(4) ----- docker swarm 初次体验
参考:https://docs.docker.com/get-started/part4/ 了解 swarm 集群 swarm 是一组运行 Docker 并且已加入集群中的机器.执行此操作后,您可以继 ...
- learning docker steps(5) ----- docker stack 初次体验
参考:https://docs.docker.com/get-started/part5/ stack 技术栈.技术栈是一组相关的服务,它们共享依赖项并且可以一起进行编排和扩展.单个技术栈能够定义和协 ...
- learning docker steps(7) ----- docker registry 搭建
参考: https://docs.docker.com/engine/reference/builder/ https://hub.docker.com/_/registry/ https://www ...
- learning docker steps(6) ----- docker 镜像加速
http://www.docker-cn.com/registry-mirror 通过 Docker 官方镜像加速,中国区用户能够快速访问最流行的 Docker 镜像.该镜像托管于中国大陆,本地用户现 ...
- 在docker中初次体验.net core 2.0
.net core的跨平台有了Linux,不能没有docker……网上的系列文章一大推,特别是docker还有了中文官网:https://www.docker-cn.com/ .上面说的很清楚了,这里 ...
- docker初次体验-管理MySQL+tomcat镜像
引言 平时经常用linux,我没少吃苦后悔linux没好好研究研究.装一些软件配一些环境时很是害怕,多亏有了docker.docker是一个应用容器引擎,可以管理很多的软件镜像,这些镜像被官方放在了d ...
随机推荐
- P3466 [POI2008]KLO-Building blocks
目录 题目 思路 错误 代码 题目 luogu csdn好像限制了展开博客次数,真的好xx 思路 显然一段区间内的值一定是他的中位数 少一点比多一点好 然后就可以枚举区间了 区间答案为 val[mid ...
- 论文笔记——Data-free Parameter Pruning for Deep Neural Networks
论文地址:https://arxiv.org/abs/1507.06149 1. 主要思想 权值矩阵对应的两列i,j,如果差异很小或者说没有差异的话,就把j列与i列上(合并,也就是去掉j列),然后在下 ...
- YOLO(Darknet官方)训练分类器
目录 1. 分类数据准备 2. Darknet配置 3. Darknet命令使用 4. cifar-10 使用示例 1. 分类数据准备 需要的文件列表: 1. train.list : 训练的图片的绝 ...
- Change the Forwarding: RMT Architecture
Change the Forwarding: RMT Architecture Note on "Forwarding Metamorphosis: Fast Programmable Ma ...
- spring +servlet 与 spring MVC
spring serlvetSpring框架中context-param与servlet中init-param的contextConfigLocation的区别https://blog.csdn.ne ...
- Win10重命名文件夹导致资源管理器卡顿的解决办法
我本机使用的是 Win10 1607,不清楚是因为什么原因导致重命名文件夹时资源管理器会被卡死,找了很长时间终于找到了解决办法,现在我把步骤粘出来以便后续遇到相同问题的朋友能及时解决. 其实操作很简单 ...
- python argparse模块--转载
add_argument:读入命令行参数,该调用有多个参数 ArgumentParser.add_argument(name or flags…[, action][, nargs][, const] ...
- Window下的git配置文件在哪里【图文】
来源:https://jingyan.baidu.com/article/870c6fc3589f22b03fe4be95.html 第一次使用码云建仓库总是提示各种错误,遂,从头在学一遍git,改篇 ...
- django 动态生成CSV文件
CSV (Comma Separated Values),以纯文本形式存储数字和文本数据的存储方式.纯文本意味着该文件是一个字符序列,不含必须像二进制数字那样的数据.CSV文件由任意数目的记录组成,记 ...
- typescripts学习
可选与默认参数 可选参数:在参数名后面,冒号前面添加一个问号,则表明该参数是可选的.如下代码: function buildName(firstName: string, lastName?: str ...