Docker - 使用 swarm 部署 services
前言
经过之前一段时间学习与思考,我们已经大概明确了一些感念: Docker image/container, service and node
简单来说,swarm允许我们以节点(node)的方式组织集群(cluster);每个节点上面可以部署一个或者多个服务(service);每个服务又可以包括一个或者多个(container)
在此,我放上Docker官方网站的结构图,方便理解。


创建网络
在部署服务之前,我们首先需要创建网络。Docker 提供了不同的方式供我们创建不同形式的网络。在这里,我们创建 overlay 模式的网络
$ docker network create --driver overlay \
--subnet 10.0.0.1/24 \
--opt encrypted \
mynetwork
-- driver 指定网络方式
-- subset 指定用于网络的子网, 如果不指定,swarm会自动选择一个子网,但是根据官网的描述这个自动指定的子网这个可能会引起container通信的问题。(before kelner 3.10)
-- opt 指定网络安全模式
创建网络完成后,我们可以查看到我们的网络
$ docker network ls

PS : 在这里贴一下官网对于network的描述,有兴趣的童鞋可以看一下
Docker Engine swarm mode natively supports overlay networks, so you can enable container-to-container networks. When you use swarm mode, you don’t need an external key-value store. Features of swarm mode overlay networks include the following:
- You can attach multiple services to the same network.
- By default, service discovery assigns a virtual IP address (VIP) and DNS entry to each service in the swarm, making it available by its service name to containers on the same network.
- You can configure the service to use DNS round-robin instead of a VIP.
In order to use overlay networks in the swarm, you need to have the following ports open between the swarm nodes before you enable swarm mode:
- Port
7946TCP/UDP for container network discovery. - Port
4789UDP for the container overlay network.
在指定网络上添加服务
$ docker service create \
--name mybusybox \
--network mynetwork \
mynetwork \ busybox \
sleep 3000
添加一个名称为mybusybox的service,这个 service 将启动找到对应的 image (如果没有会自动下载) 并且启动 container. 完成后我们可以看到 service 的信息
$ docker service ps mybusybox
再添加一个同类型的 service, 命名为tuobusybox, 在这里添加两个service是为了演示之后的夸 container 相互访问,实际情况下,应根据我们的业务需求添加 service
现在我们再查看network 信息
$docker network inspect mynetwork

这里可以看到,我们的网络“mynetwork” 下面运行着两个service
容器间通信
到这里为止,我们的 service 以及 container 已经已经创建完成。现在我们来测试下container之间的通信。
启动一个service 并且进入容器, 我这里是 mybusybox
$ docker exec -it mybusybox.1.cj3y6wgt6rry6pxei9utjufpo /bin/sh
在容器内查看另一个容器, tuobusybox

可以看到,能够使用DNS查询到 tuobusybox 服务 (service)
在mybusybox container 里面,使用 tasks.SERVICE-NAME 来查看指点 service 中所有 container 的 IP
$ nslookup tasks.tuobusybox

由于我们只启动了一个container, 所以只返回了一个IP。
OK,我们已经完成了在自己的网络下运行多个服务(容器),并且验证了容器之间的网络链接 :)
Docker - 使用 swarm 部署 services的更多相关文章
- docker kubernetes Swarm容器编排k8s CICD部署
1docker版本 docker 17.09 https://docs.docker.com/ appledeAir:~ apple$ docker version Client: Docker En ...
- docker stack /swarm 替代 docker-compose 进行部署
之前一直用docker-compose开发了几个单例的service, 今天开始压力测试, 结果发现postgres的CPU负载很重, 就想设置cpus 结果发现docker-compose V3之后 ...
- Docker管理工具 - Swarm部署记录
之前介绍了Docker集群管理工具-Kubernetes部署记录,下面介绍另一个管理工具Swarm的用法,Swarm是Docker原生的集群管理软件,与Kubernetes比起来比较简单. Swarm ...
- Docker Swarm部署集群
一.Swarm简介 Swarm是Docker的一个编排工具,参考官网:https://docs.docker.com/engine/swarm/ Swarm 模式简介 要在Swarm模式下运行dock ...
- 小白学Docker之Swarm
承接上篇文章:小白学Docker之Compose,自学网站来源于https://docs.docker.com/get-started 系列文章: 小白学Docker之基础篇 小白学Docker之Co ...
- Docker And Swarm Mode(一)
(一)节点的创建和配置 前言 虽然工作中一直在用Docker和Docker Swarm,但是总感觉有点陌生,总想自己亲手来写写和配置Docker 容器相关的事情,这篇文章主要是参考了Los Tech ...
- 基于Jenkins,docker实现自动化部署(持续交互)
前言 随着业务的增长,需求也开始增多,每个需求的大小,开发周期,发布时间都不一致.基于微服务的系统架构,功能的叠加,对应的服务的数量也在增加,大小功能的快速迭代,更加要求部署的快速化,智能化.因此 ...
- Docker Compose 一键部署LNMP
Docker Compose 一键部署LNMP 目录结构 [root@localhost ~]# tree compose_lnmp/ compose_lnmp/ ├── docker-compose ...
- Docker Compose 一键部署Nginx代理Tomcat集群
Docker Compose 一键部署Nginx代理Tomcat集群 目录结构 [root@localhost ~]# tree compose_nginx_tomcat/ compose_nginx ...
随机推荐
- 使用Mybatis时报错Cause: java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符
首先保证sql语句在oracle中的编写是正确的,然后在配置文件中插入时就报这样的错误.有可能是因为sql语句后面多了“:”分号,在标签中写分号是错的.如果我写成了 insert into emplo ...
- spring学习(6)
1 spring概念 (1)spring核心两部分 (2)spring一站式框架 (3)spring版本 可以使用基本的javaBean代替EJB,EJB是重量级框架. 1 spring是一个开源的轻 ...
- angularjs笔记(1)
https://github.com/angular/angular.js/blob/master/src/ng/q.js 1.ng-app 指令告诉 AngularJS,<div> 元素 ...
- void与其他类型的转化
#include<stdio.h> void f(void *a) { printf("%d\n",a); } int main() { int b=10; f(b); ...
- leetcode 2SUM
; i < numbers.size(); ++i){ ; i < v.size(); i++){ ; j < v.size ...
- 018对象——对象 get_class get_declared_classes get_declared_interfaces
<?php /** * 对象 get_class get_declared_classes get_declared_interfaces */ //get_class() 获得对象的类名,区分 ...
- 【lightoj-1046】Rider(BFS)
链接:http://www.lightoj.com/volume_showproblem.php?problem=1046 题意: 给m*n的棋盘,数字k代表这个位置上有棋子,并且一步可以连续跳1-k ...
- 在VMware永久修改网
如果想要永久性设置固定的IP地址,需要通过编辑网卡配置文件实现: 现在使用VI编辑器打开配置文件. # vi /etc/sysconfig/network-scripts/ifcfg-eth0 虽然直 ...
- pymysql 模块
Python3连接MySQL 介绍 PyMySQL 是在 Python3.x 版本中用于连接 MySQL 服务器的一个库,Python2中则使用mysqldb. Django中也可以使用PyMySQL ...
- HihoCoder - 1236 Scores (五维偏序,分块+bitset)
题目链接 题意:给定n个五维空间上的点,以及m组询问,每组询问给出一个点,求五个维度都不大于它的点有多少个,强制在线. 神仙题 单独考虑每个维度,把所有点按这个维度上的大小排序,然后分成T块,每块用一 ...