Docker Compose不允许访问服务。

huangapple go评论82阅读模式
英文:

Docker compose not letting access to services

问题

Here are the translated parts of your text:

我有一个基于Spring Boot、Maven和Netflix Eureka服务器设计的微服务项目。我想使用Docker Compose部署它们。然而,当我部署它们时,所有服务都在Eureka服务器上注册,但只有两个服务正常工作,而所有其他服务都出现了413客户端错误,没有任何有效的原因。以下是Docker Compose文件,

  1. ---
  2. version: '3.7'
  3. services:
  4. ## Eureka Server
  5. discovery-server:
  6. platform: linux/amd64
  7. image: hanzjk/discovery-server:latest
  8. container_name: discovery-server
  9. pull_policy: always
  10. ports:
  11. - "8761:8761"
  12. environment:
  13. - SPRING_PROFILES_ACTIVE=docker
  14. api-gateway:
  15. platform: linux/amd64
  16. image: hanzjk/api-gateway:latest
  17. container_name: api-gateway
  18. pull_policy: always
  19. ports:
  20. - "8080:8080"
  21. environment:
  22. - SPRING_PROFILES_ACTIVE=docker
  23. - LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_SECURITY=TRACE
  24. depends_on:
  25. - discovery-server
  26. ## Agora Token-Service Docker Compose Config
  27. agora-token-server:
  28. platform: linux/amd64
  29. container_name: agora-token-server
  30. pull_policy: always
  31. image: hanzjk/agora-token-server:latest
  32. environment:
  33. - SPRING_PROFILES_ACTIVE=docker
  34. depends_on:
  35. - discovery-server
  36. - api-gateway
  37. ## Avatar-Service Docker Compose Config
  38. avatar:
  39. platform: linux/amd64
  40. container_name: avatar
  41. pull_policy: always
  42. image: hanzjk/avatar:latest
  43. environment:
  44. - SPRING_PROFILES_ACTIVE=docker
  45. depends_on:
  46. - discovery-server
  47. - api-gateway
  48. ## Feedback-Service Docker Compose Config
  49. feedback:
  50. platform: linux/amd64
  51. container_name: feedback
  52. pull_policy: always
  53. image: hanzjk/feedback:latest
  54. environment:
  55. - SPRING_PROFILES_ACTIVE=docker
  56. depends_on:
  57. - discovery-server
  58. - api-gateway
  59. ## Payment-Service Docker Compose Config
  60. payment:
  61. platform: linux/amd64
  62. container_name: payment
  63. pull_policy: always
  64. image: hanzjk/payment:latest
  65. environment:
  66. - SPRING_PROFILES_ACTIVE=docker
  67. depends_on:
  68. - discovery-server
  69. - api-gateway
  70. ## Stats-Service Docker Compose Config
  71. stats:
  72. platform: linux/amd64
  73. pull_policy: always
  74. container_name: stats
  75. image: hanzjk/stats:latest
  76. environment:
  77. - SPRING_PROFILES_ACTIVE=docker
  78. depends_on:
  79. - discovery-server
  80. - api-gateway
  81. ## Auth-Service Docker Compose Config
  82. auth:
  83. platform: linux/amd64
  84. pull_policy: always
  85. container_name: auth
  86. image: hanzjk/auth:latest
  87. environment:
  88. - SPRING_PROFILES_ACTIVE=docker
  89. depends_on:
  90. - discovery-server
  91. - api-gateway
  92. ## Exhibition-Service Docker Compose Config
  93. exhibition:
  94. platform: linux/amd64
  95. container_name: exhibition
  96. pull_policy: always
  97. image: hanzjk/exhibition:latest
  98. environment:
  99. - SPRING_PROFILES_ACTIVE=docker
  100. depends_on:
  101. - discovery-server
  102. - api-gateway
  103. ## Stall-Service Docker Compose Config
  104. stall:
  105. platform: linux/amd64
  106. container_name: stall
  107. pull_policy: always
  108. image: hanzjk/stall:latest
  109. environment:
  110. - SPRING_PROFILES_ACTIVE=docker
  111. depends_on:
  112. - discovery-server
  113. - api-gateway
  114. ## Ticket-Service Docker Compose Config
  115. ticket:
  116. platform: linux/amd64
  117. container_name: ticket
  118. pull_policy: always
  119. image: hanzjk/ticket:latest
  120. environment:
  121. - SPRING_PROFILES_ACTIVE=docker
  122. depends_on:
  123. - discovery-server
  124. - api-gateway

这些服务中,只有两个没有问题,其他所有服务都出现了上述的413错误。然而,我在使用IntelliJ IDEA时没有遇到这种错误(我只使用了两个服务来上传文件,并且对它们增加了请求大小)。以下是展览服务的配置文件,

  1. server.port=8080
  2. eureka.client.serviceUrl.defaultZone=http://eureka:password@discovery-server:8761/eureka
  3. spring.servlet.multipart.max-file-size=500MB
  4. spring.servlet.multipart.max-request-size=500MB

展览服务正常运行,但货摊服务不行,它具有以下配置,

  1. server.port=8080
  2. eureka.client.serviceUrl.defaultZone=http://eureka:password@discovery-server:8761/eureka
  3. spring.servlet.multipart.max-file-size=500MB
  4. spring.servlet.multipart.max-request-size=500MB

以下是不使用文件上传的统计服务配置,

  1. server.port=8080
  2. eureka.client.serviceUrl.defaultZone=http://eureka:password@discovery-server:8761/eureka
  3. spring.data.mongodb.uri=mongodb+srv://<password>:f702kMP1Mk6nZcGn@nerambum-stats.tpeoaxj.mongodb.net/?retryWrites=true&w=majority
  4. spring.data.mongodb.database=Nerambum-Stats
  5. spring.data.mongodb.port=27017

我已根据413错误增加了请求大小,但仍然在调用API时出现该错误。

英文:

I have a microservice based project designed using Springboot, Maven, and the Netflix eureka server. I want to deploy them using Docker Compose. However, when I deployed them, all the services got registered on the eureka server, but only two services were working, and all the other services gave a 413 client side error without any valid reason. Here is the Docker Compose file,

  1. ---
  2. version: &#39;3.7&#39;
  3. services:
  4. ## Eureka Server
  5. discovery-server:
  6. platform: linux/amd64
  7. image: hanzjk/discovery-server:latest
  8. container_name: discovery-server
  9. pull_policy: always
  10. ports:
  11. - &quot;8761:8761&quot;
  12. environment:
  13. - SPRING_PROFILES_ACTIVE=docker
  14. api-gateway:
  15. platform: linux/amd64
  16. image: hanzjk/api-gateway:latest
  17. container_name: api-gateway
  18. pull_policy: always
  19. ports:
  20. - &quot;8080:8080&quot;
  21. environment:
  22. - SPRING_PROFILES_ACTIVE=docker
  23. - LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_SECURITY= TRACE
  24. depends_on:
  25. - discovery-server
  26. ## Agora Token-Service Docker Compose Config
  27. agora-token-server:
  28. platform: linux/amd64
  29. container_name: agora-token-server
  30. pull_policy: always
  31. image: hanzjk/agora-token-server:latest
  32. environment:
  33. - SPRING_PROFILES_ACTIVE=docker
  34. depends_on:
  35. - discovery-server
  36. - api-gateway
  37. ## Avatar-Service Docker Compose Config
  38. avatar:
  39. platform: linux/amd64
  40. container_name: avatar
  41. pull_policy: always
  42. image: hanzjk/avatar:latest
  43. environment:
  44. - SPRING_PROFILES_ACTIVE=docker
  45. depends_on:
  46. - discovery-server
  47. - api-gateway
  48. ## Feedback-Service Docker Compose Config
  49. feedback:
  50. platform: linux/amd64
  51. container_name: feedback
  52. pull_policy: always
  53. image: hanzjk/feedback:latest
  54. environment:
  55. - SPRING_PROFILES_ACTIVE=docker
  56. depends_on:
  57. - discovery-server
  58. - api-gateway
  59. ## Payment-Service Docker Compose Config
  60. payment:
  61. platform: linux/amd64
  62. container_name: payment
  63. pull_policy: always
  64. image: hanzjk/payment:latest
  65. environment:
  66. - SPRING_PROFILES_ACTIVE=docker
  67. depends_on:
  68. - discovery-server
  69. - api-gateway
  70. ## Stats-Service Docker Compose Config
  71. stats:
  72. platform: linux/amd64
  73. pull_policy: always
  74. container_name: stats
  75. image: hanzjk/stats:latest
  76. environment:
  77. - SPRING_PROFILES_ACTIVE=docker
  78. depends_on:
  79. - discovery-server
  80. - api-gateway
  81. ## Auth-Service Docker Compose Config
  82. auth:
  83. platform: linux/amd64
  84. pull_policy: always
  85. container_name: auth
  86. image: hanzjk/auth:latest
  87. environment:
  88. - SPRING_PROFILES_ACTIVE=docker
  89. depends_on:
  90. - discovery-server
  91. - api-gateway
  92. ## Exhibition-Service Docker Compose Config
  93. exhibition:
  94. platform: linux/amd64
  95. container_name: exhibition
  96. pull_policy: always
  97. image: hanzjk/exhibition:latest
  98. environment:
  99. - SPRING_PROFILES_ACTIVE=docker
  100. depends_on:
  101. - discovery-server
  102. - api-gateway
  103. ## Stall-Service Docker Compose Config
  104. stall:
  105. platform: linux/amd64
  106. container_name: stall
  107. pull_policy: always
  108. image: hanzjk/stall:latest
  109. environment:
  110. - SPRING_PROFILES_ACTIVE=docker
  111. depends_on:
  112. - discovery-server
  113. - api-gateway
  114. ## Ticket-Service Docker Compose Config
  115. ticket:
  116. platform: linux/amd64
  117. container_name: ticket
  118. pull_policy: always
  119. image: hanzjk/ticket:latest
  120. environment:
  121. - SPRING_PROFILES_ACTIVE=docker
  122. depends_on:
  123. - discovery-server
  124. - api-gateway

Here is the api gateway service configurations,

  1. server.port=8080
  2. eureka.client.serviceUrl.defaultZone=http://eureka:password@discovery-server:8761/eureka

Out of these services, only two work without any issue, and all the others give the above 413 error. However, I am not getting this kind of error, using IntelliJ idea (I am using only two services to upload files, and for them I increased the request size). Here is the configuration file for the exhibition service,

  1. server.port=8080
  2. eureka.client.serviceUrl.defaultZone=http://eureka:password@discovery-server:8761/eureka
  3. spring.servlet.multipart.max-file-size=500MB
  4. spring.servlet.multipart.max-request-size=500MB

Exhibition service is working without any issue, but not the stall service, which has the below configurations,

  1. server.port=8080
  2. eureka.client.serviceUrl.defaultZone=http://eureka:password@discovery-server:8761/eureka
  3. spring.servlet.multipart.max-file-size=500MB
  4. spring.servlet.multipart.max-request-size=500MB

Here are the stats service configurations that don't use any file uploading,

  1. server.port=8080
  2. eureka.client.serviceUrl.defaultZone=http://eureka:password@discovery-server:8761/eureka
  3. spring.data.mongodb.uri=mongodb+srv://&lt;password&gt;:f702kMP1Mk6nZcGn@nerambum-stats.tpeoaxj.mongodb.net/?retryWrites=true&amp;w=majority
  4. spring.data.mongodb.database=Nerambum-Stats
  5. spring.data.mongodb.port=27017

I have increased the request size according to the 413 error, but still it shows that error when invoking an API call.

答案1

得分: 1

问题似乎出现在服务尝试注册到Eureka时。我遇到了同样的问题,并通过将以下行添加到每个服务的配置文件中解决了它。

  1. eureka.instance.instance-id=${spring.application.name}:${random.value}

这将设置微服务的实例ID,这是注册表用于识别微服务特定实例的唯一标识符。

英文:

Looks like the issue occurs when the service tries to register with Eureka. I faced this same issue and I solved it by adding the below line to the configuration file of each service.

  1. eureka.instance.instance-id=${spring.application.name}:${random.value}

This will set the instance ID for the microservice, which is a unique identifier used by the registry to identify the specific instance of the microservice.

huangapple
  • 本文由 发表于 2023年5月10日 12:43:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76214962.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定