环境

基于上一节的env/server:v0.1, env/worker:v0.1镜像, 在基于debian8.2的两台机器上测试部署docker swarm.

docker service部署

➜  ~  docker service create --replicas  --name server -e APP_PORT= --network docker-net --publish : env/server:v0.
image env/server:v0. could not be accessed on a registry to record
its digest. Each node will access env/server:v0. independently,
possibly leading to different nodes running different
versions of the image. pzyx887jb112isgkyorarvt7t
overall progress: out of tasks
/: running [==================================================>]
verify: Service converged
➜ ~
➜ ~ docker service create --replicas --name worker -e APP_DOMAIN=server -e APP_PORT= --network docker-net env/worker:v0.
image env/worker:v0. could not be accessed on a registry to record
its digest. Each node will access env/worker:v0. independently,
possibly leading to different nodes running different
versions of the image. wavv2ie7ad9je6s33q82f3skv
overall progress: out of tasks
/: running [==================================================>]
/: running [==================================================>]
verify: Service converged
➜ ~ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
pzyx887jb112 server replicated / env/server:v0. *:->/tcp
wavv2ie7ad9j worker replicated / env/worker:v0.
➜ ~ docker service ps worker
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
hyjcg25ymfvx worker. env/worker:v0. debian-vm Running Running seconds ago
zpx2oq4q0dhu worker. env/worker:v0. debian Running Running seconds ago  
 ➜  ~  docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a9b1931acf12 env/worker:v0. "python worker.py" minutes ago Up minutes worker..zpx2oq4q0dhuqgvtkt0mm8dyt
994e4779c252 env/server:v0. "python server.py" minutes ago Up minutes server..v5mu7wa8tfswayzwjh3u1qtpk
➜ ~ docker exec 994e4779c252 cat /env/server/log/server.log
-- :: [INFO] Waiting for connection...
-- :: [INFO] ('10.0.0.5', ) connected
-- :: [INFO] ('10.0.0.4', ) connected
➜ ~ docker exec a9b1931acf12 cat /env/worker/log/worker.log
-- :: [INFO] [+] ('10.0.0.2', ) connected
-- :: [INFO] [recv] hello, docker!
➜ ~ docker exec a9b1931acf12 ping -c server
PING server (10.0.0.2) () bytes of data.
bytes from 10.0.0.2: icmp_seq= ttl= time=0.117 ms
bytes from 10.0.0.2: icmp_seq= ttl= time=0.205 ms --- server ping statistics ---
packets transmitted, received, % packet loss, time 1000ms
rtt min/avg/max/mdev = 0.117/0.161/0.205/0.044 ms

manager node上测试服务可用和可发现

 root@debian-vm:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
94b6e94a4f4c env/worker:v0. "python worker.py" About a minute ago Up seconds worker..hyjcg25ymfvx2u6ghy3ng7g1y
root@debian-vm:~# docker exec 94b6e94a4f4c cat /env/worker/log/worker.log
-- :: [INFO] [+] ('10.0.0.2', ) connected
-- :: [INFO] [recv] hello, docker!
root@debian-vm:~# docker exec 94b6e94a4f4c ping -c server
PING server (10.0.0.2) () bytes of data.
bytes from 10.0.0.2: icmp_seq= ttl= time=0.058 ms
bytes from 10.0.0.2: icmp_seq= ttl= time=0.057 ms --- server ping statistics ---
packets transmitted, received, % packet loss, time 1002ms
rtt min/avg/max/mdev = 0.057/0.057/0.058/0.007 ms
root@debian-vm:~#

worker node上测试服务可用和可发现

# 从worker node上验证publish端口
root@debian-vm:/env/worker# export APP_PORT=
root@debian-vm:/env/worker# export APP_DOMAIN=192.168.2.118
root@debian-vm:/env/worker# python worker.py
[+] ('192.168.2.118', ) connected
[+][recv] hello, docker!
^C
[-] signal() received, exit!
root@debian-vm:/env/worker# # 从manager node上验证publish端口
➜ worker export APP_PORT=
➜ worker export APP_DOMAIN=192.168.2.118
➜ worker python worker.py
[+] ('192.168.2.118', ) connected
[+][recv] hello, docker!
^C
[-] signal() received, exit!
➜ worker docker exec 994e4779c252 cat /env/server/log/server.log
-- :: [INFO] Waiting for connection...
-- :: [INFO] ('10.0.0.5', ) connected
-- :: [INFO] ('10.0.0.4', ) connected
-- :: [INFO] ('10.255.0.2', ) connected
-- :: [INFO] ('10.255.0.2', ) closed
-- :: [INFO] ('10.255.0.2', ) connected
-- :: [INFO] ('10.255.0.2', ) closed
➜ worker

验证服务的publish端口

docker stack部署

#docker-compose.yml

version: ""
services:
server:
image: env/server:v0.
build:
context: /app/env/server
dockerfile: Dockerfile
labels:
description: "tcp server test script"
ports:
- :${APP_PORT-}
- ${APP_PORT-}:${APP_PORT-}
restart: always
environment:
- APP_PORT=${APP_PORT-}
networks:
- overlay
deploy:
replicas: worker:
image: env/worker:v0.
build: /app/env/worker
labels:
description: "tcp client test script"
links:
- server
environment:
- APP_PORT=${APP_PORT-}
- APP_DOMAIN=server
networks:
- overlay
depends_on:
- server
deploy:
replicas:
restart_policy:
condition: on-failure worker_test:
image: env/worker_test:v0.
networks:
- overlay
deploy:
replicas: networks:
overlay:
➜  /env  echo $APP_PORT

➜  /env  docker stack deploy -c docker-compose.yml  env
Ignoring unsupported options: build, links, restart Creating network env_overlay
Creating service env_worker_test
Creating service env_server
Creating service env_worker
➜ /env docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
lwl5gpaseyz5 env_server replicated / env/server:v0. *:->/tcp, *:->/tcp
0ywtuy79e5af env_worker replicated / env/worker:v0.
a2malzyjs8a8 env_worker_test replicated / env/worker_test:v0.
➜ /env docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6534e1ab7a0f env/worker:v0. "python worker.py" About a minute ago Up About a minute env_worker..o8oo0c2do3xi17bb2y1jyxyvt
a6f05a1180fa env/worker_test:v0. "python worker.py" About a minute ago Up About a minute env_worker_test..xyriek6uv0jt5u8grfh2r2nip
dd178c531cab env/worker_test:v0. "python worker.py" About a minute ago Up About a minute env_worker_test..e5akyik75zru3a3vm7t0uow42
➜ /env docker exec 6534e1ab7a0f cat /env/worker/log/worker.log
-- :: [INFO] [+] ('10.0.3.8', ) connected
-- :: [INFO] [recv] hello, docker!
 root@debian-vm:/# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
54816f125b5d env/worker:v0. "python worker.py" minutes ago Up minutes env_worker..583qka4f0we1tr8gzfbfwd8xq
b148b68c60ac env/worker:v0. "python worker.py" minutes ago Up minutes env_worker..pajhjlgfcfpkcvtgbl4pd9iec
4501dddabc12 env/server:v0. "python server.py" minutes ago Up minutes env_server..r8rffhrzds0p5qreiz3zskglt
423f9f7fe5bf env/worker_test:v0. "python worker.py" minutes ago Up minutes env_worker_test..yafiu0eg5bmmv47do4dwtbcdm
root@debian-vm:/# docker exec 4501dddabc12 cat /env/server/log/server.log
-- :: [INFO] Waiting for connection...
-- :: [INFO] ('10.0.3.3', ) connected
-- :: [INFO] ('10.0.3.3', ) connected
-- :: [INFO] ('10.0.3.2', ) connected
root@debian-vm:/#

manager node验证连接建立成功

# worker node启动客户端
➜ worker export APP_PORT=
➜ worker export APP_DOMAIN=192.168.2.118
➜ worker python worker.py
[+] ('192.168.2.118', ) connected
[+][recv] hello, docker!
^C
[-] signal() received, exit!
➜ worker # manager node查看日志, 验证连接成功
root@debian-vm:/# docker exec 4501dddabc12 cat /env/server/log/server.log
-- :: [INFO] Waiting for connection...
-- :: [INFO] ('10.0.3.3', ) connected
-- :: [INFO] ('10.0.3.3', ) connected
-- :: [INFO] ('10.0.3.2', ) connected
-- :: [INFO] ('10.255.0.2', ) connected
-- :: [INFO] ('10.255.0.2', ) closed
root@debian-vm:/#

验证服务的publish端口

容器基础(八): 使用docker swarm部署程序的更多相关文章

  1. 容器基础(七): 使用docker compose部署程序

    配置 在上一节的基础上,  增加如下的docker-compose.yml文件, 然后用docker-compose up命令启动容器进行部署: version: " services: s ...

  2. 从零开始,使用Docker Swarm部署集群教程

    本文首先从Dockerfile创建了一个简单web镜像 然后将web镜像推送到了远程仓库,以备后面集群中不同机器自动下载 之后使用docker-compose.yml配置了一个应用 而后新建了2台虚拟 ...

  3. Docker Swarm部署集群

    一.Swarm简介 Swarm是Docker的一个编排工具,参考官网:https://docs.docker.com/engine/swarm/ Swarm 模式简介 要在Swarm模式下运行dock ...

  4. docker swarm 部署服务时,限制服务启动后所在的机器

    借助容器技术,可以方便的在不同环境下部署服务,保证服务环境的一致性.docker swarm这个东西,可以方便的对容器进行编排管理. docker swarm集群中,有manager节点与worker ...

  5. docker swarm部署spring cloud服务

    一.准备docker swarm的集群环境 ip 是否主节点   192.168.91.13 是   192.168.91.43 否   二.准备微服务 ①eureka服务 application.y ...

  6. Centos7部署FytSoa项目至Docker——第三步:部署程序

    FytSoa项目地址:https://gitee.com/feiyit/FytSoaCms 部署完成地址:http://82.156.127.60:8000/ 我买的是一年99标准型SA2云服务器 购 ...

  7. Docker三剑客之Docker Swarm

    一.什么是Docker Swarm Swarm是Docker公司推出的用来管理docker集群的平台,几乎全部用GO语言来完成的开发的,代码开源在https://github.com/docker/s ...

  8. 【09】循序渐进学 docker:docker swarm

    写在前面的话 至此,docker 的基础知识已经了解的差不多了,接下来就来谈谈对于 docker 容器,我们如何来管理它. docker swarm 在学习 docker swarm 之前,得先知道容 ...

  9. Docker Swarm——集群管理

    前言 之前在总结docker machine的时候,当时对docker理解还不够深入,甚至还不知道 docker machine 与 docker swarm 的区别. 在查阅资料以及官方文档之后,今 ...

随机推荐

  1. scala性能测试

    主要对比scala 的for, while循环,以及和java for while循环作对比 scala代码 object TestScalaClass { var maxindex = 100000 ...

  2. ListItem Updating事件监视有没有上传附件

    using System; using System.Collections.Generic; using System.Text; using Microsoft.SharePoint; using ...

  3. SpringBoot非官方教程 | 第十四篇:在springboot中用redis实现消息队列

    转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot14-redis-mq/ 本文出自方志朋的博客 这 ...

  4. springboot jar 部署到linux之后 获取类资源文件问题-- 仅限linux 下 情况比较特殊 需要获取打到jar内的 讲台资源 只能通过流获取,根据路径获取不到指定文件 nullpointExption

    https://blog.csdn.net/qq_27000425/article/details/72897282 ClassPathResource类,如果没有指定相对的类名,该类将从类的根路径开 ...

  5. HTML页面常用的编辑框

    public class FormInputUtil { /** * 获取表单中的InputText * * @param name * @param rs * @return */ public s ...

  6. harbor中碰到的问题

    harbor部署整体比较简单,但是就是这么简单的东西稍微改变点配置文件就会有不小的问题 1.问题1 部署harbor1.6发现web界面删除的镜像在push一遍上去后,镜像大小为0 且无法删除,这个问 ...

  7. django+xadmin在线教育平台(十七)

    8-1 课程列表 拷贝课程列表页到template目录 创建课程相关的urls.py Mxonline2/urls.py中声明包含到course的url中: # 课程app的url配置 url(r&q ...

  8. windows下openresty中使用lua做接口转发、二次封装等

    需求:根据客户需求,可以在ngx下 通过lua做接口二次封装再次转发给用户或第三方 场景:对返回值有要求的.接口屏蔽字段.或做一些业务上的验证等 1.windows直接下载openresty 解压即可 ...

  9. gcc 手动安装

    由于公司内部服务器没有联通外网,只能苦逼的手动安装gcc(自带的版本太老) rpm -ivh ppl-0.10.2-11.el6.x86_64.rpm rpm -ivh cloog-ppl-0.15. ...

  10. QQ群排名霸屏技术居然是这样简单

    最近做了一些收费的QQ群,收多少钱,一块钱的入门费,也就是说进入我的QQ群必须要1块钱的会费. 我的QQ群主要是干嘛呢,放些电影,比如说市面上电影院,正在播放的,最新最热门的,火爆的一些电影. 先前呢 ...