learning docker steps(4) ----- docker swarm 初次体验
参考:https://docs.docker.com/get-started/part4/
了解 swarm 集群
swarm 是一组运行 Docker 并且已加入集群中的机器。执行此操作后,您可以继续运行已使用的 Docker 命令,但现在它们在集群上由 swarm 管理节点执行。 swarm 中的机器可以为物理或虚拟机。加入 swarm 后,可以将它们称为节点。
swarm 管理节点可以使用多项策略来运行容器,例如“最空的节点”– 这将使用容器填充使用最少的机器。或“全局”,这将确保每台机器恰好获得指定容器的一个实例。您可以指示 swarm 管理节点使用 Compose 文件中的这些策略,就像您已使用的策略一样。
swarm 管理节点是 swarm 中可以执行命令或授权其他机器加入 swarm 作为工作节点的唯一机器。工作节点仅用于提供功能,并且无权告知任何其他机器它可以做什么和不能做什么。
在前面我们学习了docker services 在本地机器创建5个副本,这次我们可以docker swarm来体验一下在两台机器内,创建5个副本,这5个副本不在同一台机器上,实现真正的集群并且有负载均衡的功能。
首先我们得先来安培装一个工具docker-machine,
参考 :https://docs.docker.com/machine/install-machine/
$ base=https://github.com/docker/machine/releases/download/v0.14.0 && \
curl -L $base/docker-machine-$(uname -s)-$(uname -m) >/tmp/docker-machine && \
sudo install /tmp/docker-machine /usr/local/bin/docker-machine
先创建两台机器:
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker-machine create –driver virtualbox myvm1
Running pre-create checks…
(myvm1) No default Boot2Docker ISO found locally, downloading the latest release…
(myvm1) Latest release for github.com/boot2docker/boot2docker is v18.06.1-ce
(myvm1) Downloading /root/.docker/machine/cache/boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v18.06.1-ce/boot2docker.iso…
(myvm1) 0%….10%….20%….30%….40%….50%….60%….70%….80%….90%….100%
Creating machine…
(myvm1) Copying /root/.docker/machine/cache/boot2docker.iso to /root/.docker/machine/machines/myvm1/boot2docker.iso…
(myvm1) Creating VirtualBox VM…
(myvm1) Creating SSH key…
(myvm1) Starting the VM…
(myvm1) Check network to re-create if needed…
(myvm1) Found a new host-only adapter: “vboxnet0”
(myvm1) Waiting for an IP…
Waiting for machine to be running, this may take a few minutes…
Detecting operating system of created instance…
Waiting for SSH to be available…
Detecting the provisioner…
Provisioning with boot2docker…
Copying certs to the local machine directory…
Copying certs to the remote machine…
Setting Docker configuration on the remote daemon…
Checking connection to Docker…
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env myvm1
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker-machine create –driver virtualbox myvm2
Running pre-create checks…
Creating machine…
(myvm2) Copying /root/.docker/machine/cache/boot2docker.iso to /root/.docker/machine/machines/myvm2/boot2docker.iso…
(myvm2) Creating VirtualBox VM…
(myvm2) Creating SSH key…
(myvm2) Starting the VM…
(myvm2) Check network to re-create if needed…
(myvm2) Waiting for an IP…
Waiting for machine to be running, this may take a few minutes…
Detecting operating system of created instance…
Waiting for SSH to be available…
Detecting the provisioner…
Provisioning with boot2docker…
Copying certs to the local machine directory…
Copying certs to the remote machine…
Setting Docker configuration on the remote daemon…
Checking connection to Docker…
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env myvm2
查看创建的docker-machine:
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
myvm1集群初始化:
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker-machine ssh myvm1 “docker swarm init –advertise-addr 192.168.99.100:2376”
Swarm initialized: current node (mwy9dpd6ea1bqzvhqpi4j2ov3) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join –token SWMTKN-1-1n6a2nkkkutdrij7hdg71hih8x5c2l7oanxa08dmvm9u20kli4-3okzvyjr4hpzu8j4q7ldhfchb 192.168.99.100:2377
To add a manager to this swarm, run ‘docker swarm join-token manager’ and follow the instructions.
myvm2加入集群当中:
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker-machine ssh myvm2 “docker swarm join –token SWMTKN-1-1n6a2nkkkutdrij7hdg71hih8x5c2l7oanxa08dmvm9u20kli4-3okzvyjr4hpzu8j4q7ldhfchb 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 “docker node ls”
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
mwy9dpd6ea1bqzvhqpi4j2ov3 * myvm1 Ready Active Leader 18.06.1-ce
ecvpnan32s3oug4h28bf66rxl myvm2 Ready Active 18.06.1-ce
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker-machine env myvm1
export DOCKER_TLS_VERIFY=”1″
export DOCKER_HOST=”tcp://192.168.99.100:2376″
export DOCKER_CERT_PATH=”/root/.docker/machine/machines/myvm1″
export DOCKER_MACHINE_NAME=”myvm1″
# Run this command to configure your shell:
# eval $(docker-machine env myvm1)
eval指令是为了登录myvm1做次备:
root@vmuser-virtual-machine:/home/vmuser/workdir/services# eval $(docker-machine env myvm1)
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
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 node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
mwy9dpd6ea1bqzvhqpi4j2ov3 * myvm1 Ready Active Leader 18.06.1-ce
ecvpnan32s3oug4h28bf66rxl myvm2 Ready Active 18.06.1-ce
docker@myvm1:~$ exit
将docker-compose.yml传到myvm1当中:
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker-machine scp docker-compose.yml myvm1:~
docker-compose.yml 100% 371 72.8KB/s 00:00
在myvm1上面创建服务:
root@vmuser-virtual-machine:/home/vmuser/workdir/services# docker-machine ssh myvm1 “docker stack deploy -c docker-compose.yml getstartedlab”
Creating network getstartedlab_webnet
Creating service getstartedlab_web
通过如下指令我们可以看到5个副本当中2个副本在myvm1当中,3个副本在myvm2当中,从而所现本地化集群:
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
y597za9yvdcb getstartedlab_web.1 pan19881018/get-start:part2 myvm2 Running Preparing 20 seconds ago
0x8gp8t2r8v2 getstartedlab_web.2 pan19881018/get-start:part2 myvm1 Running Preparing 20 seconds ago
qwkkru77pyib getstartedlab_web.3 pan19881018/get-start:part2 myvm2 Running Preparing 20 seconds ago
v7jry6xie03j getstartedlab_web.4 pan19881018/get-start:part2 myvm2 Running Preparing 20 seconds ago
cucyq1fdgzbh getstartedlab_web.5 pan19881018/get-start:part2 myvm1 Running Preparing 20 seconds ago
learning docker steps(4) ----- docker swarm 初次体验的更多相关文章
- 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(5) ----- docker stack 初次体验
参考:https://docs.docker.com/get-started/part5/ stack 技术栈.技术栈是一组相关的服务,它们共享依赖项并且可以一起进行编排和扩展.单个技术栈能够定义和协 ...
- learning docker steps(3) ----- docker services 初次体验
参考:https://docs.docker.com/get-started/part3/#docker-composeyml docker 的 service样例, 我们可以理解成是一个本地负载均衡 ...
- 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 swarm - 使用体验 1+2
背景 凭借敏捷开发部署理念的推行,相信对于很多人来说docker这项容器技术已经并不陌生,Docker 1.12引擎发布了快两个月,新引擎中包含了许多特性.诸如: Swarm模式,容器集群的健康检查, ...
随机推荐
- uboot 网络驱动模型
原文:https://blog.csdn.net/zhouxinlin2009/article/details/45390065 UBOOT的PHYCHIP配置 PHYCHIP的配置位于 includ ...
- Python3基础 函数 递归 阶乘与斐波那契数列
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 ** 幂运算 // 整除运算
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- (转)Spring Boot(一)
(二期)4.springboot的综合讲解 [课程四]springbo...概念.xmind64.5KB [课程四]spring装配方式.xmind0.2MB [课程四预习]spri...解读.xmi ...
- 51NOD 1057 N的阶乘
1057 N的阶乘 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 输入N求N的阶乘的准确值. Input 输入N(1 <= N <= 10000) ...
- 论文笔记——Rethinking the Inception Architecture for Computer Vision
1. 论文思想 factorized convolutions and aggressive regularization. 本文给出了一些网络设计的技巧. 2. 结果 用5G的计算量和25M的参数. ...
- Pytorch版本yolov3源码阅读
目录 Pytorch版本yolov3源码阅读 1. 阅读test.py 1.1 参数解读 1.2 data文件解析 1.3 cfg文件解析 1.4 根据cfg文件创建模块 1.5 YOLOLayer ...
- ZOJ 3869 Ace of Aces
There is a mysterious organization called Time-Space Administrative Bureau (TSAB) in the deep univer ...
- ubuntu 14.04 安装 gflags
1.下载 git clone https://github.com/gflags/gflags 2.编译 进入源码目录(即gflags文件夹) cmake . make -j 24 sudo make ...
- 关于C#中的日期的一个简单总结
首先,总结两个简单的方法,实现 秒 与 日期 的相互转换: public class MyTest { /// <summary> /// 将Unix时间戳转换为DateTime类型时间, ...