Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 在Docker上的Eureka中获取正确的域名_Spring_Docker_Docker Compose_Netflix Zuul_Netflix Eureka - Fatal编程技术网

Spring 在Docker上的Eureka中获取正确的域名

Spring 在Docker上的Eureka中获取正确的域名,spring,docker,docker-compose,netflix-zuul,netflix-eureka,Spring,Docker,Docker Compose,Netflix Zuul,Netflix Eureka,我正在微服务体系结构上使用Spring框架,并使用带有自签名证书的HTTPS(*.mydomainname.fr)。 作为注册表,我使用Eureka,作为代理,我使用Zuul。因此,由于我的证书,我的服务必须以名称“service name”.mydomainname.fr在Eureka上注册。此外,我目前没有使用DNS,我只是在/etc/hosts(127.0.0.1 register.bec3.fr)中手动添加域名 我想在docker compose中添加我的所有服务。 我的docker-c

我正在微服务体系结构上使用Spring框架,并使用带有自签名证书的HTTPS(
*.mydomainname.fr
)。
作为注册表,我使用Eureka,作为代理,我使用Zuul。因此,由于我的证书,我的服务必须以名称
“service name”.mydomainname.fr
在Eureka上注册。此外,我目前没有使用DNS,我只是在
/etc/hosts
127.0.0.1 register.bec3.fr
)中手动添加域名

我想在docker compose中添加我的所有服务。 我的docker-compose.yml是:

version: '3'
services:
    registration-service:
        image: maven:alpine
        container_name: register.bec3.fr
        working_dir: /usr/src/spring-boot-app
        volumes:
         - ./scripts:/usr/src/spring-boot-app/scripts
         - ./sslcert:/usr/src/spring-boot-app/ssl
         - ./registration-service:/usr/src/spring-boot-app
         - ./.m2:/root/.m2
        expose: 
         - 8761
        entrypoint: bash -c "keytool -noprompt -import -alias ioteam.bec3 -file /usr/src/spring-boot-app/ssl/ioteam.pem -keystore /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts -storepass xxxxxx && mvn -Dspring.profiles.active=docker spring-boot:run"
        #entrypoint: bash -c "/usr/src/spring-boot-app/scripts/addhosts.sh && keytool -noprompt -import -alias ioteam.bec3 -file /usr/src/spring-boot-app/ssl/ioteam.pem -keystore /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts -storepass xxxxxx && mvn -Dspring.profiles.active=docker spring-boot:run"
        ports: 
         - 8761:8761
        networks: 
          back-net:
            ipv4_address: 172.20.0.5
            aliases:
              - register.bec3.fr
        depends_on:
         - "maria"

proxy-service:
    image: maven:alpine
    container_name: proxy.bec3.fr
    working_dir: /usr/src/spring-boot-app
    volumes:
     - ./scripts:/usr/src/spring-boot-app/scripts
     - ./sslcert:/usr/src/spring-boot-app/ssl
     - ./proxy-service:/usr/src/spring-boot-app
     - ./.m2:/root/.m2
    expose: 
     - 8888
    entrypoint: bash -c "keytool -noprompt -import -alias ioteam.bec3 -file /usr/src/spring-boot-app/ssl/ioteam.pem -keystore /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts -storepass xxxxxx && mvn -Dspring.profiles.active=docker spring-boot:run"
    #entrypoint: bash -c "/usr/src/spring-boot-app/scripts/addhosts.sh && keytool -noprompt -import -alias ioteam.bec3 -file /usr/src/spring-boot-app/ssl/ioteam.pem -keystore /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts -storepass xxxxxx && mvn -Dspring.profiles.active=docker spring-boot:run"
    ports: 
     - 8888:8888
    networks: 
      back-net:
        ipv4_address: 172.20.0.6
        aliases:
          - proxy.bec3.fr
    depends_on:
     - "registration-service"

auth-service:
    image: maven:alpine
    container_name: auth.bec3.fr
    working_dir: /usr/src/spring-boot-app
    volumes:
     - ./scripts:/usr/src/spring-boot-app/scripts
     - ./sslcert:/usr/src/spring-boot-app/ssl
     - ./auth-service:/usr/src/spring-boot-app
     - ./.m2:/root/.m2
    expose: 
     - 9999
    entrypoint: bash -c "keytool -noprompt -import -alias ioteam.bec3 -file /usr/src/spring-boot-app/ssl/ioteam.pem -keystore /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts -storepass xxxxxx && mvn -Dspring.profiles.active=docker spring-boot:run"
    #entrypoint: bash -c "/usr/src/spring-boot-app/scripts/addhosts.sh && keytool -noprompt -import -alias ioteam.bec3 -file /usr/src/spring-boot-app/ssl/ioteam.pem -keystore /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts -storepass xxxxxx && mvn -Dspring.profiles.active=docker spring-boot:run"
    ports: 
     - 9999:9999
    networks: 
      back-net:
        ipv4_address: 172.20.0.7
        aliases:
          - auth.bec3.fr
    depends_on:
     - "maria"
     - "registration-service"

maria:
    build:
        context: ./
        dockerfile: maria-dev/Dockerfile
    image: maria:latest
    container_name: maria
    environment:
     - MYSQL_ROOT_PASSWORD=xxxxxx
    networks:
      back-net:
        ipv4_address: 172.20.0.3

networks:
  back-net:
    driver: bridge
    ipam:
     config:
     - subnet: 172.20.0.0/24
因此,由于我的应用程序中的该参数,我的服务可以注册到我的注册服务。Properties:

eureka.client.service-url.defaultZone=https://register.bec3.fr:8761/eureka/
我的问题是,当我启动这些服务时,我的eureka仪表板上有docker ID:

  • 72959xxxxx:auth:9999
  • c0f1c4xxxxx:代理:8888

我需要这样的东西:

  • auth.mydomainname.fr:auth:9999
  • proxy.mydomainname.fr:proxy:8888
因为我的证书。没有这一点,我就不能卷曲身体去服务:

curl -i -XPOST "https://web_app:@register.bec3.fr:8888/auth/oauth/token" -d "grant_type=password&username=toto&password=toto" --cacert my-cert.crt
我能做什么?我可以在Eureka中使用自定义主机名,还是应该更改Docker配置?
谢谢你的帮助。

我也有同样的问题。这是为了概念验证,所以我解决它的方法有点脏

实际上,您在eureka仪表板中得到了72959AXXX:auth:9999,您需要auth.mydomainname.fr:auth:9999

解决方案是在服务docker的/etc/hosts顶部添加此服务的域名。尝试使用此脚本执行此操作:

#!/bin/bash

HOSTS="/etc/hosts"
TMP1="tmp1"
TMP2="tmp2"
IP="192.168.1.1"
DN="domainenameservice"

SERVICE="$IP\t$DN"

echo -e $SERVICE > $TMP1
cat $TMP1 $HOSTS > $TMP2

echo "# test" > $HOSTS
while IFS= read -r var
do
  echo "$var" >> $HOSTS
done < $TMP2
#/bin/bash
HOSTS=“/etc/HOSTS”
TMP1=“TMP1”
TMP2=“TMP2”
IP=“192.168.1.1”
DN=“域名服务”
SERVICE=“$IP\t$DN”
echo-e$服务>$TMP1
cat$TMP1$HOSTS>$TMP2
echo“#test”>$HOSTS
而IFS=读取-r变量
做
回显“$var”>>$HOSTS
完成<$TMP2