环境

基于上一节的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. 指令过滤器orderBy

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  2. SQL on&where&having

    on.where.having这三个都可以加条件的子句中,on是最先执行,where次之,having最后.有时候如果这先后顺序不影响中间结果的话,那最终结果是相同的.但因为on是先把不符合条件的记录 ...

  3. 对TCP三次握手四次分手还不清楚,超简单解析

      关于TCP三次握手四次分手,之前看资料解释的都很笼统,很多地方都不是很明白,所以很难记,前几天看的一个博客豁然开朗,可惜现在找不到了.现在把之前的疑惑总结起来,方便一下大家. 先上个TCP三次握手 ...

  4. 原生js方面的兼容性问题

    1.关于获取行外样式 currentStyle 和 getComputedStyle 出现的兼容性问题  我们都知道js通过style不可以获取行外样式,当我们需要获取行外样式时:  我们一般通过这两 ...

  5. SP1716 GSS3 - Can you answer these queries III(单点修改,区间最大子段和)

    题意翻译 nnn 个数, qqq 次操作 操作0 x y把 AxA_xAx​ 修改为 yyy 操作1 l r询问区间 [l,r][l, r][l,r] 的最大子段和 题目描述 You are give ...

  6. java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=testSelect], {ExactMatcher:fDisplayName=testSelect(cool.zsn.Dao.UserMapperTest)], {LeadingIdentifierMatcher:fClassName=cool.zsn

    @Before:每次调用类中的方法,都会先执行@Before下的方法 @Before下的方法应该是  public : @Before public void init() { application ...

  7. java 时间转换去杠

    public static String minusHyphen(String dateParam){ if(dateParam ==null) return null; if(dateParam.i ...

  8. [转]ThinkPHP5 隐藏index.php问题

    ThinkPHP5 隐藏index.php问题 Apache,修改.htaccess文件 ----------------------------------------------------- R ...

  9. python并发编程之多进程、多线程、异步、协程、通信队列Queue和池Pool的实现和应用

    什么是多任务? 简单地说,就是操作系统可以同时运行多个任务.实现多任务有多种方式,线程.进程.协程. 并行和并发的区别? 并发:指的是任务数多余cpu核数,通过操作系统的各种任务调度算法,实现用多个任 ...

  10. 第1章 MATLAB概述

    MATLAB系统由~开发环境.~语言.~数学函数库.~图形处理系统.~应用程序接口(API)5大部分组成. 界面 命令行中的语句格式 命令行的语句格式:>>变量=表达式(没有>> ...