Port mappings are no longer used here because there are problems with feign based on Docker hostname on different hosts.
Copy the good packaged jar into the Docker image.
There are several services, just copy a few dockerfile
Dockerfile
from registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144# maintainer Zhenweilai <181282945@qq .com>COPY jar/usr/localRUN cp/usr/share/zoneinfo/asia/shanghai/etc/localtime && \ ' Asia/shanghai ' >/etc/timezone
Open two Eureka, register with each other
Open two API services,
Open two app services.
Open a Zuul routing service
Docker-compose
Version: ' 2 ' services:eureka_master:build:eurekaserver network_mode: ' Host ' command:java-jar/usr/local/eure Kaserver.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/MICR Oservice/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/m Icroservice/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-E Ureka_backup volumes:-/usr/local/microservice/log:/usr/locAl/microservice/log restart:always Api_8071:build:api network_mode: "Host" command:java-jar/usr/local/a Pi.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_mod E: "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/l Og:/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/l Ocal/microservice/log:/usr/local/microservice/log restart:always
Apply APPLICATION.YML, register to two x Eureka
Eureka: instance: appname:app instance-id: ${spring.cloud.client.ipaddress}:${server.port} # Renew Update interval lease-renewal-interval-in-seconds:10 #续约到期时间 lease-expiration-duration-in-seconds:30 Client: serviceurl: defaultzone:http://username:[email protected]:8000/eureka/,http://username:[email protected]: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: #关闭自我保护 enable-self-preservation:false # 5 Seconds to clear the eviction-interval-timer-in-ms:5 client: register-with-eureka:true fetch-registry: True service-url: defaultzone:http://username:[email protected]${eureka.instance.other-hostname}:${ eureka.instance.other-port}/eureka/
Input command: Docker-compose up--build-d
Step: from registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144---> 1b97d252ae81step 2/4: Maintainer Zhenweilai<181282945@qq. com>---> Using cache---> bf31044329bestep 3/4: COPY jar/usr/local---> 7a1be0756dcaremoving Intermediate cont Ainer 5c45807bbc81step 4/4: RUN cp/usr/share/zoneinfo/asia/shanghai/etc/localtime && echo ' Asia/shanghai ' & Gt;/etc/timezone---> Running in e8988ea8a1f8---> ad26f883175eremoving intermediate container E8988ea8a1f8successfully built ad26f883175esuccessfully tagged microservice_eureka_backup:latestbuilding eureka_ Masterstep: from registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144---> 1b97d252ae81step 2/4: MAINTAINER Zhenweilai<181282945@qq. com>---> Using cache---> Bf31044329bestep 3/4: COPY jar/usr/local---> Using cache---> 7a1be0756dcastep 4 /4:run cp/usr/share/zoneinfo/asia/shanghai/etc/localtime && Echo ' Asia/shanghai ' >/etc/timezone---> Using Cache---> ad26f883175esuccessfully built ad26f883175esuccessfully tagged Microservice_eureka_master: Latestbuilding cloudinvoice_8080step: from registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144---> 1b97d252ae81step 2/4: Maintainer Zhenweilai<181282945@qq. com>---> Using cache---> Bf31044329bestep 3/4: COPY jar/usr/local---> Using cache---> B9fe90218b85step 4 /4:run cp/usr/share/zoneinfo/asia/shanghai/etc/localtime && Echo ' Asia/shanghai ' >/etc/timezone---> Using Cache---> 709a728e383asuccessfully built 709a728e383asuccessfully tagged microservice_cloudinvoice_8080: Latestbuilding cloudinvoice_8060step: from registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144---> 1b97d252ae81step 2/4: Maintainer Zhenweilai<181282945@qq. com>---> Using cache---> Bf31044329bestep 3/4: COPY jar/usr/local---> Using cache---> B9fe90218b85step 4 /4:run cp/usr/share/zoneinfo/asia/shanghai/etc/localtime && Echo ' Asia/shanghai ' >/etc/timezone---> Using Cache---> 709a728e383asuccessfully built 709a728e383asuccessfully tagged microservice_cloudinvoice_8060: Latestbuilding api_8070step: from registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144---> 1b97d252ae81step 2/4: Maintainer Zhenweilai<181282945@qq. com>---> Using cache---> Bf31044329bestep 3/4: COPY jar/usr/local---> Using cache---> 5b85563136e5step 4 /4:run cp/usr/share/zoneinfo/asia/shanghai/etc/localtime && Echo ' Asia/shanghai ' >/etc/timezone---> Using Cache---> 679564f7d414successfully built 679564f7d414successfully tagged microservice_api_8070: Latestbuilding api_8071step: from registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144---> 1b97d252ae81step 2/4: Maintainer Zhenweilai<181282945@qq. com>---> Using cache---> Bf31044329bestep 3/4: COPY jar/usr/local---> Using cache---> 5b85563136e5step 4 /4:run cp/usr/share/zoneinfo/asia/shanghai/etc/localtime && Echo ' Asia/shanghai ' >/etc/timezone---> Using Cache---> 679564f7d414successfully built 679564f7d414successfully tagged microservice_api_8071: Latestbuilding routerstep: from registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144---> 1b97d252ae81Step 2 /4:maintainer Zhenweilai<181282945@qq. com>---> Using cache---> Bf31044329bestep 3/4: COPY jar/usr/local---> Using cache---> C88e35c7fc38step 4 /4:run cp/usr/share/zoneinfo/asia/shanghai/etc/localtime && Echo ' Asia/shanghai ' >/etc/timezone---> Using Cache---> 288ce24cfef0successfully built 288ce24cfef0successfully tagged Microservice_router: Latestrecreating microservice_eureka_master_1 ... Recreating microservice_eureka_backup_1 ... Recreating microservice_eureka_master_1recreating microservice_eureka_backup_1 ... doneRecreating microservice_app_ 8060_1 ... Recreating microservice_api_8070_1 ... Recreating microservice_api_8070_1recreating microservice_router_1 ... Recreating microservice_api_8071_1 ... Recreating microservice_cloudinvoice_8060_1recreating microservice_api_8071_1recreating microservice_app_8080_1 ... Recreating microservice_router_1recreating 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 Full package release, multi-service, multi-node spring CLOUD, EUREKA cluster