Before the various cluster configuration, you can call the service, but the service here url unavailable-replicas always present, means not available. After various attempts, the end, or by clustering the hostname of the way, but the application service, or clustering calls over IP.
Various failures, Baidu for a long time, finally found the article. problem solved. Before confusion is how docker container to set the hosts file.
Reference article: https: //blog.csdn.net/benben_2015/article/details/88426438
The final release of this writing the script.
// define a URL, it is the cluster address.
= UREKA_SERVICEURL " HTTP: // test8761: 8761 / Eureka /, HTTP: // test8762: 8762 / Eureka /, HTTP: // test8763: 8763 / Eureka / "
Run Services SH " Docker RUN --restart = Always -p 8761 : 8761 " + " -d $ {-v} log_path: log_path $ {} " +
// Center address Register " -e eureka.client.serviceUrl.defaultZone EUREKA_SERVICEURL = $ {} " +
// container name " -e Eureka = test8761 .instance.hostname " +
// focus is on this line, host file three additional addresses. Eventually into the container in the / etc / hosts file also saw three addresses. "--add-host=test8761:192.168.89.130 --add-host=test8762:192.168.89.130 --add-host=test8763:192.168.89.130 "+ "--name ${PROJECT_NAME} "+ " $REPOSITORY"
Check into the container
[the root Master @ ~ ] # Docker PS ========== See vessel all running CONTAINER ID PORTS the STATUS the IMAGE CREATED the COMMAND NAMES 7e8a4101623c 192.168 . 89.132 / MYBS-Cloud / Eureka: 0.0 . . 1 -SNAPSHOT " -Djava.securit ... the Java " 19 minutes ago Member Up 19 minutes 0.0 . 0.0 : 8763 -> 8761 / tcp eureka8763 707bb1f2dc5c 192.168 . 89.132/mybs-cloud/eureka:0.0.1-SNAPSHOT "java -Djava.securit…" 19 minutes ago Up 19 minutes 0.0.0.0:8762->8761/tcp eureka8762 24636b410d2d 192.168.89.132/mybs-cloud/eureka:0.0.1-SNAPSHOT "java -Djava.securit…" 19 minutes ago Up 19 minutes 0.0.0.0:8761->8761/tcp eureka [root@master ~]# docker exec -it 24636b410d2d /bin/bash ===========进入容器 root@24636b410d2d:/# cat /etc/host =======查看hosts文件 host.conf hostname hosts hosts.allow hosts.deny root@24636b410d2d:/# cat /etc/hosts 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters 192.168.89.130 test8761 192.168.89.130 test8762 192.168.89.130 test8763 172.17.0.3 24636b410d2d root@24636b410d2d:/#
the Node ( " $ {nodeTag} " ) { // Docker private warehouse registry DEF REGISTRY_URL = " 192.168.89.132 " DEF REGISTRY_UID = " ADMIN " DEF REGISTRY_PID = " Harbor12345 " // private warehouse home name DEF MAIN_NAME = " MS- Cloud " // project directory directory DEF PROJECT_NAME = " $ {} projectName " // item version DEF PROJECT_VERSION = " 0.0.1-SNAPSHOT " // image name DEF = the REPOSITORY "${REGISTRY_URL}/${MAIN_NAME}/${PROJECT_NAME}:${PROJECT_VERSION}" // 日志路径 def LOG_PATH="/home/date/logs/${PROJECT_NAME}/" // 注册中心eureka地址 def EUREKA_SERVICEURL="http://192.168.89.130:8761/eureka/,http://192.168.89.130:8762/eureka/,http://192.168.89.130:8763/eureka/" stage('start') { sh "date +'%Y-%m-%d %H:%M:%S'" } stage("1、clear ${PROJECT_NAME}") { echo "clearing ${PROJECT_NAME}..." sh "docker stop ${PROJECT_NAME} |true" sh "docker rm -f ${PROJECT_NAME} |true" sh "docker image rm $REPOSITORY |true" } stage("2、deploy ${PROJECT_NAME}") { echo "deploying ${PROJECT_NAME}..." sh "docker login -u ${REGISTRY_UID} -p ${REGISTRY_PID} ${REGISTRY_URL}" if (PROJECT_NAME == "ms-base-eureka") { EUREKA_SERVICEURL="http://test8761:8761/eureka/,http://test8762:8762/eureka/,http://test8763:8763/eureka/" sh "docker run --restart=always -p 8761:8761 "+ "-d -v ${LOG_PATH}:${LOG_PATH} "+ "-e eureka.client.serviceUrl.defaultZone=${EUREKA_SERVICEURL} "+ "-e eureka.instance.hostname=test8761 "+ "--add-host=test8761:192.168.89.130 --add-host=test8762:192.168.89.130 --add-host=test8763:192.168.89.130 "+ "--name ${PROJECT_NAME} "+ " $REPOSITORY" sh "docker rm -f ${PROJECT_NAME}8762 |true" sh "docker run --restart=always -p 8762:8761 "+ "-d -v ${LOG_PATH}8762:${LOG_PATH} "+ "-e eureka.client.serviceUrl.defaultZone=${EUREKA_SERVICEURL} "+ "-e eureka.instance.hostname=test8762 "+ "--add-host=test8761:192.168.89.130 --add-host=test8762:192.168.89.130 --add-host=test8763:192.168.89.130 "+ "--name ${PROJECT_NAME}8762 "+ " $REPOSITORY" sh "docker rm -f ${PROJECT_NAME}8763 |true" sh "docker run --restart=always -p 8763:8761 "+ "-d -v ${LOG_PATH}8763:${LOG_PATH} "+ "-e eureka.client.serviceUrl.defaultZone=${EUREKA_SERVICEURL} "+ "-e eureka.instance.hostname=test8763 "+ "--add-host=test8761:192.168.89.130 --add-host=test8762:192.168.89.130 --add-host=test8763:192.168.89.130 "+ "--name ${PROJECT_NAME}8763 "+ " $REPOSITORY" } else if (PROJECT_NAME == "ms-base-config") { sh "docker run --restart=always -p 8888:8888 "+ "-d -v ${LOG_PATH}:${LOG_PATH} "+ "-e eureka.client.serviceUrl.defaultZone=${EUREKA_SERVICEURL} "+ "--name ${PROJECT_NAME} "+ " $REPOSITORY" } else { error ''Please select the branch you want to publish } } stage('Results 3') { echo "finish ${PROJECT_NAME}" } stage('end') { sh "date +'%Y-%m-%d %H:%M:%S'" echo "本次运行时间: ${currentBuild.duration} ms" } }