spring-boot - 当在Dockers上部署时,Spring Cloud Config Server在URL -http://localhost:8888上提供了Connect Timeout Exception

标签 spring-boot docker docker-compose microservices spring-cloud-config-server

我试图将我的spring-boot微服务转移到docker。当在本地系统上的STS上实现时,我的微服务运行得非常好。但是,当我对它们进行dockerize时,会出现连接超时错误。
我在下面分享我的代码段:
Docker撰写:

version: '3.6'
services:
  db:
    image: 'mysql:8.0.18'
    container_name: mysqldb
    ports:
      - '3300:3300'
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_USER=root
    networks:
      - truyum-nw
      - movie-cruiser-nw
    volumes:
      - './mysqldb:/var/lib/mysql'
      - './dbscripts:/docker-entrypoint-initdb.d'
  config-server:
    image: spring-cloud-config-server
    build: ./spring-cloud-config-server
    container_name: spring-cloud-config-server
    ports:
      - '8888:8888'
    networks:
      - truyum-nw
      - movie-cruiser-nw
  eureka:
    image: eureka-discovery-service
    build: ./eureka-discovery-service
    container_name: eureka-discovery
    ports:
      - '8761:8761'
    depends_on:
      - config-server
      - db
    networks:
      - truyum-nw
      - movie-cruiser-nw
  zuul:
    image: zuul-service
    build: ./zuul-gateway
    container_name: zuul-bridge
    ports:
      - '8762:8762'
    depends_on:
      - eureka
      - config-server
    networks:
      - truyum-nw
      - movie-cruiser-nw
  auth-service:
    image: auth-service
    build: ./Authentication-service
    container_name: auth-service
    ports:
      - '9100:9100'
    depends_on:
      - eureka
      - config-server
    networks:
      - truyum-nw
      - movie-cruiser-nw
  menu-item-service:
    image: menu-item-service
    build: ./menuitem-service
    container_name: menu-item-service
    ports:
      - '34000:34000'
    depends_on:
      - eureka
      - config-server
      - zuul
      - db
      - auth-service
    networks:
      - truyum-nw
  cart-service:
    image: cart-service
    build: ./cart-service
    container_name: cart-service
    ports:
      - '34001:34001'
    depends_on:
      - eureka
      - config-server
      - zuul
      - db
      - menu-item-service
      - auth-service
    networks:
      - truyum-nw
  movie-service:
    image: movie-service
    build: ./movie-service
    container_name: movie-service
    ports:
      - '35000:35000'
    depends_on:
      - eureka
      - config-server
      - db
      - zuul
      - auth-service
    networks:
      - movie-cruiser-nw
  favourite-service:
    image: favourite-service
    build: ./favorite-service
    container_name: favourite-service
    ports:
      - '35001:35001'
    depends_on:
      - eureka
      - config-server
      - db
      - zuul
      - auth-service
      - movie-service
    networks:
      - movie-cruiser-nw
networks:
  truyum-nw:
    name: truyum-nw
    driver: bridge
  movie-cruiser-nw:
    name: movie-cruiser-nw
    driver: bridge
application.properties spring-cloud-config-server :
spring.cloud.config.server.git.uri = https://github.com/satyamthedeveloper/Stage4_Week2_841418_SatyamKumar
server.port=8888
application.properties Eureka 发现服务器:
spring.application.name=discoveryservice
spring.cloud.config.uri = http://spring-cloud-config-server:8888

 
当我执行docker-compose up并检查http://localhost:8888/discoveryservice/default时,我得到的结果为
{
    "name": "discoveryservice",
    "profiles": [
        "default"
    ],
    "label": null,
    "version": "8450532e432fb103ef30d0002fa254b23d2158d6",
    "state": null,
    "propertySources": [
        {
            "name": "https://github.com/satyamthedeveloper/Stage4_Week2_841418_SatyamKumar/discoveryservice.properties",
            "source": {
                "server.port": "8761",
                "eureka.client.register-with-eureka": "false",
                "eureka.client.fetch-registry": "false",
                "info.app.name": "Spring Eureka Server Application"
            }
        },
        {
            "name": "https://github.com/satyamthedeveloper/Stage4_Week2_841418_SatyamKumar/application.yml",
            "source": {
                "eureka.client.service-url.defaultZone": "http://eureka-discovery:8761/eureka",
                "logging.level.org.springframework.web": "DEBUG",
                "management.endpoints.web.exposure.include": "*"
            }
        }
    ]
}
但是,我的Eureka discovery service从8080开始,因为我没有公开它,所以无法访问。我尝试了其中一些步骤,但无济于事。
  • 尝试在我的云配置启动并准备就绪时停止并重新启动发现服务。
  • 通过创建网络仍然没有用,没有docker-compose分别尝试了它。

  • 我不确定为什么我的服务无法获取可以使用URL轻松获取的链接。
    This is a screenshot of my log which I get every time, no matter whatever I try.

    最佳答案

    您在 Eureka (eureka)配置中必须为配置服务器引用的名称仅为config-server,因为这是您撰写yaml中的服务名称。

    关于spring-boot - 当在Dockers上部署时,Spring Cloud Config Server在URL -http://localhost:8888上提供了Connect Timeout Exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62800536/

    相关文章:

    java - Spring Retry - 异常问题和重试

    java - 在java中使用thymeleaf html模板下载pdf文件时,css样式不可见

    windows - Windows 服务器 2012r2 上的 Docker

    docker - Docker中的默认参数

    Docker-compose 卷不复制任何文件

    python - Docker 容器中缺少 python 包

    docker - 如何在我的 CMD 脚本中设置环境变量

    java - MongoDB:如何优化大数据的聚合查询

    Spring Boot 应用程序独立运行,但在 tomcat 7.X 中部署时不起作用

    java - 将 sprig 连接到 kafka 开始使用 docker compose 进行本地主机开发