Docker部署springcloud(有问题)

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
将文件上传服务器
image.png
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
image.png
启动完毕
image.png

访问eureka

image.png

发现config没有注册到eureka
很奇怪不知道怎么排查~~~哭
网上查了一下好像是网络的问题而且配置简单可能也是问题...

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。