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 ...
随机推荐
- 20145334赵文豪网络对抗Web安全基础实践
1.SQL注入攻击原理,如何防御? SQL注入攻击就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意SQL命令的目的. 对于SQL注入攻击的防范,我觉 ...
- Android实践项目汇报(四)
全国天气客户端 本周学习计划 添加修改功能,完成项目 实际完成情况 1.成功显示当天及后几天的天气信息 通过修改chaxun.java程序,比较JSON数据格式中JSONObject("to ...
- P3709 大爷的字符串题
题意 询问区间众数出现的次数 思路 唯有水题快人心 离散化+莫队 莫队一定要先加后减,有事会出错的 莫队维护区间众数: 维护两个数组,一个数组记录权值为x的出现次数,一个记录出现次数为x的数的个数 a ...
- SPOJ ADAFIELD Ada and Field(STL的使用:set,multiset,map的迭代器)题解
题意:n*m的方格,“0 x”表示x轴在x位置切一刀,“0 y”表示y轴在y位置切一刀,每次操作后输出当前面积最大矩形. 思路:用set分别储存x轴y轴分割的点,用multiset(可重复)储存x轴y ...
- Goldbach`s Conjecture(素筛水题)题解
Goldbach`s Conjecture Goldbach's conjecture is one of the oldest unsolved problems in number theory ...
- Winform中使用折叠窗口
使用此处的控件 http://www.codeproject.com/Articles/18401/XPanderControls 注意事项 使用之前需要先添加winform自带的toolStripC ...
- 会员通过消费攒积分,升级RENEW以及降级的需求
需求看上去及其简单,如下: 用文字描述就开始不容易了. 先按等级排个序,根据下一个等级,推前一个等级: --C---B----V-----A 在计算一下升级需要的积分:--C表示普通会员-----需要 ...
- MVC修改视图的默认路径
概述:之前MVC5和之前的版本中,我们要想对View文件的路径进行控制的话,则必须要对IViewEngine接口的FindPartialView或FindView方法进行重写,所有的视图引擎都继承于该 ...
- 牛客练习赛7 E 珂朵莉的数列
珂朵莉的数列 思路: 树状数组+高精度 离散化不知道哪里写错了,一直wa,最后用二分写的离散化 哪位路过大神可以帮我看看原来的那个离散化错在哪里啊 通过代码: import java.math.Big ...
- Unity另外一套简单日志控制系统
using UnityEngine; public class LogPrintf { static LogLevel logLevel = LogLevel.LOG_LEVEL_ERROR; pub ...