Spring Cloud Netflix | Eureka not registering when deployed on ECS

北战南征 提交于 2020-01-06 08:47:10

问题


I am trying to deploy Spring Netflix Eureka and related microservice application using ECS and Cloudformation.

Eureka is not able to register the related microservices because the docker images are not able to link on hostname.

Please suggest what should be the best solution to handle this.


回答1:


You should use EC2 instance's host ip instead of docker container host's. In your microservices (if those are spring boot applications), put this code:

@Bean
@Profile("docker")
public EurekaInstanceConfigBean eurekaInstanceConfig() {
    EurekaInstanceConfigBean config = new EurekaInstanceConfigBean();
    AmazonInfo info = AmazonInfo.Builder.newBuilder().autoBuild("eureka");
    config.setDataCenterInfo(info);
    info.getMetadata().put(AmazonInfo.MetaDataKey.publicHostname.getName(), info.get(AmazonInfo.MetaDataKey.publicIpv4));
    config.setHostname(info.get(AmazonInfo.MetaDataKey.publicHostname));
    config.setIpAddress(info.get(AmazonInfo.MetaDataKey.publicIpv4));
    config.setNonSecurePort(port);
    return config;
}

Remember to enable 'docker' profile in spring boot configuration.



来源:https://stackoverflow.com/questions/48995689/spring-cloud-netflix-eureka-not-registering-when-deployed-on-ecs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!