我正在尝试将我的 spring-boot 微服务转移到码头工人。在本地系统上的 STS 上实施时,我的微服务运行得非常好。但是当我将它们 dockerize 时,我得到一个连接超时错误。
我在下面分享我的代码片段:
码头工人组成:
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
spring-cloud-config-server的application.properties:
spring.cloud.config.server.git.uri = https://github.com/satyamthedeveloper/Stage4_Week2_841418_SatyamKumar
server.port=8888
Eureka-Discovery-Server的application.properties:
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 轻松获取的链接。