这里不再使用 端口映射的方式,因为不同主机上,Feign 根据 docker hostname访问会有问题.

把打包的好jar copy到docker镜像里

有几个服务,就复制几个dockerfile

Dockerfile

FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144

#
MAINTAINER zhenweilai <181282945@qq.com> COPY jar /usr/local RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo 'Asia/Shanghai' >/etc/timezone

开启两个eureka,互相注册

开启两个api服务,

开启两个app服务.

开启一个zuul路由服务

docker-compose

version: '2'
services:
eureka_master:
build: eurekaserver
network_mode: "host"
command: java -jar /usr/local/eurekaserver.jar --spring.profiles.active=test --eureka.instance.hostname=eureka1 --eureka.instance.other-hostname=eureka2 --server.port=8000 --eureka.instance.other-port=8001
volumes:
- /usr/local/microservice/log:/usr/local/microservice/log
restart: always eureka_backup:
build: eurekaserver
network_mode: "host"
command: java -jar /usr/local/eurekaserver.jar --spring.profiles.active=test --eureka.instance.hostname=eureka2 --eureka.instance.other-hostname=eureka1 --server.port=8001 --eureka.instance.other-port=8000
volumes:
- /usr/local/microservice/log:/usr/local/microservice/log
restart: always api_8070:
build: api
network_mode: "host"
command: java -jar /usr/local/api.jar --spring.profiles.active=test --server.port=8070
depends_on:
- eureka_master
- eureka_backup
volumes:
- /usr/local/microservice/log:/usr/local/microservice/log
restart: always api_8071:
build: api
network_mode: "host"
command: java -jar /usr/local/api.jar --spring.profiles.active=test --server.port=8071
depends_on:
- eureka_master
- eureka_backup
volumes:
- /usr/local/microservice/log:/usr/local/microservice/log
restart: always router:
build: router
network_mode: "host"
command: java -jar /usr/local/router.jar --spring.profiles.active=test --server.port=8088
depends_on:
- eureka_master
- eureka_backup
volumes:
- /usr/local/microservice/log:/usr/local/microservice/log
restart: always app_8060:
build: app
network_mode: "host"
command: java -jar /usr/local/app.jar --spring.profiles.active=test --server.port=8060
depends_on:
- eureka_master
- eureka_backup
volumes:
- /usr/local/microservice/log:/usr/local/microservice/log
restart: always app_8080:
build: app
network_mode: "host"
command: java -jar /usr/local/app.jar --spring.profiles.active=test --server.port=8080
depends_on:
- eureka_master
- eureka_backup
volumes:
- /usr/local/microservice/log:/usr/local/microservice/log
restart: always

应用application.yml,注册到两个eureka

eureka:
instance:
appname: app
instance-id: ${spring.cloud.client.ipAddress}:${server.port}
#续约更新时间间隔
lease-renewal-interval-in-seconds: 10
#续约到期时间
lease-expiration-duration-in-seconds: 30
client:
serviceUrl:
defaultZone: http://username:password@eureka1:8000/eureka/,http://username:password@eureka2:8001/eureka/

eureka application.yml

eureka:
instance:
hostname: localhost
other-port: 8001
other-hostname: backup
appname: eureka-server
instance-id: ${spring.cloud.client.ipAddress}:${server.port}
lease-expiration-duration-in-seconds: 5
server:
#5秒清理一次
eviction-interval-timer-in-ms: 5
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://username:password@${eureka.instance.other-hostname}:${eureka.instance.other-port}/eureka/

输入命令:docker-compose up --build -d

Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
---> 1b97d252ae81
Step 2/4 : MAINTAINER zhenweilai <@qq.com>
---> Using cache
---> bf31044329be
Step 3/4 : COPY jar /usr/local
---> 7a1be0756dca
Removing intermediate container 5c45807bbc81
Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
---> Running in e8988ea8a1f8
---> ad26f883175e
Removing intermediate container e8988ea8a1f8
Successfully built ad26f883175e
Successfully tagged microservice_eureka_backup:latest
Building eureka_master
Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
---> 1b97d252ae81
Step 2/4 : MAINTAINER zhenweilai <@qq.com>
---> Using cache
---> bf31044329be
Step 3/4 : COPY jar /usr/local
---> Using cache
---> 7a1be0756dca
Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
---> Using cache
---> ad26f883175e
Successfully built ad26f883175e
Successfully tagged microservice_eureka_master:latest
Building cloudinvoice_8080
Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
---> 1b97d252ae81
Step 2/4 : MAINTAINER zhenweilai <@qq.com>
---> Using cache
---> bf31044329be
Step 3/4 : COPY jar /usr/local
---> Using cache
---> b9fe90218b85
Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
---> Using cache
---> 709a728e383a
Successfully built 709a728e383a
Successfully tagged microservice_cloudinvoice_8080:latest
Building cloudinvoice_8060
Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
---> 1b97d252ae81
Step 2/4 : MAINTAINER zhenweilai <@qq.com>
---> Using cache
---> bf31044329be
Step 3/4 : COPY jar /usr/local
---> Using cache
---> b9fe90218b85
Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
---> Using cache
---> 709a728e383a
Successfully built 709a728e383a
Successfully tagged microservice_cloudinvoice_8060:latest
Building api_8070
Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
---> 1b97d252ae81
Step 2/4 : MAINTAINER zhenweilai <@qq.com>
---> Using cache
---> bf31044329be
Step 3/4 : COPY jar /usr/local
---> Using cache
---> 5b85563136e5
Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
---> Using cache
---> 679564f7d414
Successfully built 679564f7d414
Successfully tagged microservice_api_8070:latest
Building api_8071
Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
---> 1b97d252ae81
Step 2/4 : MAINTAINER zhenweilai <@qq.com>
---> Using cache
---> bf31044329be
Step 3/4 : COPY jar /usr/local
---> Using cache
---> 5b85563136e5
Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
---> Using cache
---> 679564f7d414
Successfully built 679564f7d414
Successfully tagged microservice_api_8071:latest
Building router
Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
---> 1b97d252ae81
Step 2/4 : MAINTAINER zhenweilai <@qq.com>
---> Using cache
---> bf31044329be
Step 3/4 : COPY jar /usr/local
---> Using cache
---> c88e35c7fc38
Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
---> Using cache
---> 288ce24cfef0
Successfully built 288ce24cfef0
Successfully tagged microservice_router:latest
Recreating microservice_eureka_master_1 ...
Recreating microservice_eureka_backup_1 ...
Recreating microservice_eureka_master_1
Recreating microservice_eureka_backup_1 ... done
Recreating microservice_app_8060_1 ...
Recreating microservice_api_8070_1 ...
Recreating microservice_api_8070_1
Recreating microservice_router_1 ...
Recreating microservice_api_8071_1 ...
Recreating microservice_cloudinvoice_8060_1
Recreating microservice_api_8071_1
Recreating microservice_app_8080_1 ...
Recreating microservice_router_1
Recreating microservice_app_8080_1 ... done

docker-compose ps

              Name                            Command               State   Ports
---------------------------------------------------------------------------------
microservice_api_8070_1 java -jar /usr/local/api ... Up
microservice_api_8071_1 java -jar /usr/local/api ... Up
microservice_app_8060_1 java -jar /usr/local/app ... Up
microservice_app_8080_1 java -jar /usr/local/app... Up
microservice_eureka_backup_1 java -jar /usr/local/eurek ... Up
microservice_eureka_master_1 java -jar /usr/local/eurek ... Up
microservice_router_1 java -jar /usr/local/route ... Up

192.168.51.60:8000

docker-compose 完整打包发布, 多服务,多节点SPRING CLOUD ,EUREKA 集群的更多相关文章

  1. Spring Cloud微服务笔记(三)服务治理:Spring Cloud Eureka快速入门

    服务治理:Spring Cloud Eureka 一.服务治理 服务治理是微服务架构中最为核心和基础的模块,它主要用来实现各个微服务实例的自动化注册与发现. 1.服务注册: 在服务治理框架中,通常会构 ...

  2. Docker Compose搭建Redis一主二从三哨兵高可用集群

    一.Docker Compose介绍 https://docs.docker.com/compose/ Docker官方的网站是这样介绍Docker Compose的: Compose是用于定义和运行 ...

  3. spring cloud深入学习(二)-----服务注册中心spring cloud eureka

    服务治理 主要用来实现各个微服务实例的自动化注册与发现,为啥需要这玩意呢?在一开始比如A系统调用B服务,可能通过手工维护B服务的实例,并且还得采用负载均衡等方式,这些全部都得需要手工维护,等后面系统越 ...

  4. 第三章 服务治理:Spring Cloud Eureka

    Spring Cloud Eureka是Spring Cloud Netflix 微服务套件中的一部分,它基于Netflix Eureka做了二次封装,主要负责完成微服务架构中的服务治理功能.Spri ...

  5. 微服务架构之spring cloud eureka

    Spring Cloud Eureka是spring cloud的核心组件,负责服务治理功能,起到中心枢纽作用,其它组件都依赖eureka来获取服务,然后再根据项目需求实现自己的业务,eureka在整 ...

  6. 第三章 服务治理: Spring Cloud Eureka

    Spring Cloud Eureka是 Spring Cloud Netflix微服务套件中的一部分,它基于Netflix Eureka做了二次封装,主要负责完成微服务架构中的服务治理功能 服务治理 ...

  7. 服务治理:Spring Cloud Eureka

    Spring Cloud Eureka主要负责完成微服务架构中服务治理功能. 服务治理是微服务架构中最为核心和基础模块,主要用来实现各个微服务实例的自动注册和发现. 服务注册 微服务实例启动后向注册中 ...

  8. 微服务架构集大成者—Spring Cloud (转载)

    软件是有生命的,你做出来的架构决定了这个软件它这一生是坎坷还是幸福. 本文不是讲解如何使用Spring Cloud的教程,而是探讨Spring Cloud是什么,以及它诞生的背景和意义. 1 背景 2 ...

  9. 主流微服务一站式解决方案Spring Cloud Alibaba入门看这篇就足够了

    学习路线 **本人博客网站 **IT小神 www.itxiaoshen.com 生态概述 架构演进 什么是微服务 https://martinfowler.com/microservices/ Mic ...

随机推荐

  1. mac对比class文件

    下载反编译工具 wget https://varaneckas.com/jad/jad158g.mac.intel.zip 设置Beyond Compare 填写编译工具路径

  2. MySQL--pt-osc工具学习

    ##=====================================================##pt-osc之工作流程:1.检查更改表是否有主键或唯一索引,是否有触发器2.检查修改表 ...

  3. 通过 ['1', '2', '3'].map(parseInt) 学习 map 和 parseInt 函数

    看到一道笔试题: ['1', '2', '3'].map(parseInt) 这道题目中涉及到 map 和 parseInt 函数的运用,如果对这两个函数的理解不充分的话,是很难思考出正确的结果的. ...

  4. 《.NET 设计规范》第 4 章:类型设计规范

    第 4 章:类型设计规范 4.1 类型和命名空间 要用命名空间把类型组织成一个由相关的功能区所构成的层次结构中. 避免非常深的命名空间层次.因为用户需要经常回找,所以这样的层次浏览起来很困难. 避免有 ...

  5. [Android] Toast问题深度剖析(一)

    欢迎大家前往云+社区,获取更多腾讯海量技术实践干货哦~ 题记 Toast 作为 Android 系统中最常用的类之一,由于其方便的api设计和简洁的交互体验,被我们所广泛采用.但是,伴随着我们开发的深 ...

  6. 部署eolinker开源版接口管理

    想找一个API接口管理的软件,为了安全性和扩展性考虑,希望是开源的,而且可以在内网独立部署.网上翻找了资料,经过一份比对之后,最终采用eolinker.过去有使用过RAP,但是感觉界面实在是太丑了. ...

  7. ORACLE 建表语句(表名及字段名大写)

    ORACLE建表时如果表名或者字段名存在大小写同时存在的情况下,默认为区分大小写,此时在select/updata等操作时需要在表名或者字段名上添加双引号,否则会报"视图不存在"的 ...

  8. BZOJ 1367: [Baltic2004]sequence [可并堆 中位数]

    1367: [Baltic2004]sequence Time Limit: 20 Sec  Memory Limit: 64 MBSubmit: 1111  Solved: 439[Submit][ ...

  9. Dapper入门教程(二)——执行非查询语句

    描述 你可以从任意实现IDbConnection的类对象中调用Dapper的扩展方法"Execute".它能够执行一条命令(Command)一次或者多次,并返回受影响的行数.这个方 ...

  10. TensorFlow实战之Softmax Regression识别手写数字

         关于本文说明,本人原博客地址位于http://blog.csdn.net/qq_37608890,本文来自笔者于2018年02月21日 23:10:04所撰写内容(http://blog.c ...