我试图将我的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开始,因为我没有公开它,所以无法访问。我尝试了其中一些步骤,但无济于事。我不确定为什么我的服务无法获取可以使用URL轻松获取的链接。
最佳答案
您在 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/