Eureka主类
package com.forezp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
Eureka application.yml
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
register-with-eureka: false
fetch-registry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
Eureka Dockerfile
FROM openjdk:8
VOLUME /tmp
ADD eureka-server-0.0.1-SNAPSHOT.jar app.jar
#RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
EXPOSE 8761
Config主类
package com.forezp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@EnableConfigServer
@EnableEurekaClient
@RestController
public class ConfigClientApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigClientApplication.class, args);
}
@RequestMapping(value = "/hi")
public String hi(){
return "foo";
}
}
Config application.yml
spring:
application:
name: config
profiles:
active: native
eureka:
instance:
non-secure-port: ${server.port:8888}
metadata-map:
instanceId: ${spring.application.name}:${random.value}
client:
service-url:
defaultZone: http://${eureka.host:localhost}:${eureka.port:8761}/eureka/
Config Dockerfile
FROM openjdk:8
VOLUME /tmp
ADD config-client-0.0.1-SNAPSHOT.jar app.jar
#RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
EXPOSE 8761
将文件上传服务器
docker-compose.yml
config:
image: "config"
hostname: config
links:
- eureka
environment:
EUREKA_HOST: eureka
EUREKA_POST: 8761
ports:
- "8888:8888"
eureka:
image: "eureka"
hostname: eureka
ports:
- "8761:8761"
到docker上部署
systemctl start docker
docker build -t eureka .
docker build -t config .
docker-compose up
启动完毕
访问eureka
发现config没有注册到eureka
很奇怪不知道怎么排查~~~哭
网上查了一下好像是网络的问题而且配置简单可能也是问题...