Docker Compose不允许访问服务。

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

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文件,

---
version: '3.7'
services:
  ## Eureka Server
  discovery-server:
    platform: linux/amd64
    image: hanzjk/discovery-server:latest
    container_name: discovery-server
    pull_policy: always
    ports:
      - "8761:8761"
    environment:
      - SPRING_PROFILES_ACTIVE=docker

  api-gateway:
    platform: linux/amd64
    image: hanzjk/api-gateway:latest
    container_name: api-gateway
    pull_policy: always
    ports:
      - "8080:8080"
    environment:
      - SPRING_PROFILES_ACTIVE=docker
      - LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_SECURITY=TRACE
    depends_on:
      - discovery-server

  ## Agora Token-Service Docker Compose Config
  agora-token-server:
    platform: linux/amd64
    container_name: agora-token-server
    pull_policy: always
    image: hanzjk/agora-token-server:latest
    environment:
      - SPRING_PROFILES_ACTIVE=docker
    depends_on:
      - discovery-server
      - api-gateway

  ## Avatar-Service Docker Compose Config
  avatar:
    platform: linux/amd64
    container_name: avatar
    pull_policy: always
    image: hanzjk/avatar:latest
    environment:
      - SPRING_PROFILES_ACTIVE=docker
    depends_on:
      - discovery-server
      - api-gateway

  ## Feedback-Service Docker Compose Config
  feedback:
    platform: linux/amd64
    container_name: feedback
    pull_policy: always
    image: hanzjk/feedback:latest
    environment:
      - SPRING_PROFILES_ACTIVE=docker
    depends_on:
      - discovery-server
      - api-gateway

  ## Payment-Service Docker Compose Config
  payment:
    platform: linux/amd64
    container_name: payment
    pull_policy: always
    image: hanzjk/payment:latest
    environment:
      - SPRING_PROFILES_ACTIVE=docker
    depends_on:
      - discovery-server
      - api-gateway

  ## Stats-Service Docker Compose Config
  stats:
    platform: linux/amd64
    pull_policy: always
    container_name: stats
    image: hanzjk/stats:latest
    environment:
      - SPRING_PROFILES_ACTIVE=docker
    depends_on:
      - discovery-server
      - api-gateway

  ## Auth-Service Docker Compose Config
  auth:
    platform: linux/amd64
    pull_policy: always
    container_name: auth
    image: hanzjk/auth:latest
    environment:
      - SPRING_PROFILES_ACTIVE=docker
    depends_on:
      - discovery-server
      - api-gateway

  ## Exhibition-Service Docker Compose Config
  exhibition:
    platform: linux/amd64
    container_name: exhibition
    pull_policy: always
    image: hanzjk/exhibition:latest
    environment:
      - SPRING_PROFILES_ACTIVE=docker
    depends_on:
      - discovery-server
      - api-gateway

  ## Stall-Service Docker Compose Config
  stall:
    platform: linux/amd64
    container_name: stall
    pull_policy: always
    image: hanzjk/stall:latest
    environment:
      - SPRING_PROFILES_ACTIVE=docker
    depends_on:
      - discovery-server
      - api-gateway

  ## Ticket-Service Docker Compose Config
  ticket:
    platform: linux/amd64
    container_name: ticket
    pull_policy: always
    image: hanzjk/ticket:latest
    environment:
      - SPRING_PROFILES_ACTIVE=docker
    depends_on:
      - discovery-server
      - api-gateway

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

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

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

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

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

server.port=8080
eureka.client.serviceUrl.defaultZone=http://eureka:password@discovery-server:8761/eureka
spring.data.mongodb.uri=mongodb+srv://<password>:f702kMP1Mk6nZcGn@nerambum-stats.tpeoaxj.mongodb.net/?retryWrites=true&w=majority
spring.data.mongodb.database=Nerambum-Stats
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,

---
version: &#39;3.7&#39;
services:
## Eureka Server
discovery-server:
platform: linux/amd64
image: hanzjk/discovery-server:latest
container_name: discovery-server
pull_policy: always
ports:
- &quot;8761:8761&quot;
environment:
- SPRING_PROFILES_ACTIVE=docker
api-gateway:
platform: linux/amd64
image: hanzjk/api-gateway:latest
container_name: api-gateway
pull_policy: always
ports:
- &quot;8080:8080&quot;
environment:
- SPRING_PROFILES_ACTIVE=docker
- LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_SECURITY= TRACE
depends_on:
- discovery-server
## Agora Token-Service Docker Compose Config
agora-token-server:
platform: linux/amd64
container_name: agora-token-server
pull_policy: always
image: hanzjk/agora-token-server:latest
environment:
- SPRING_PROFILES_ACTIVE=docker
depends_on:
- discovery-server
- api-gateway
## Avatar-Service Docker Compose Config
avatar:
platform: linux/amd64
container_name: avatar
pull_policy: always
image: hanzjk/avatar:latest
environment:
- SPRING_PROFILES_ACTIVE=docker
depends_on:
- discovery-server
- api-gateway
## Feedback-Service Docker Compose Config
feedback:
platform: linux/amd64
container_name: feedback
pull_policy: always
image: hanzjk/feedback:latest
environment:
- SPRING_PROFILES_ACTIVE=docker
depends_on:
- discovery-server
- api-gateway
## Payment-Service Docker Compose Config
payment:
platform: linux/amd64
container_name: payment
pull_policy: always
image: hanzjk/payment:latest
environment:
- SPRING_PROFILES_ACTIVE=docker
depends_on:
- discovery-server
- api-gateway
## Stats-Service Docker Compose Config
stats:
platform: linux/amd64
pull_policy: always
container_name: stats
image: hanzjk/stats:latest
environment:
- SPRING_PROFILES_ACTIVE=docker
depends_on:
- discovery-server
- api-gateway
## Auth-Service Docker Compose Config
auth:
platform: linux/amd64
pull_policy: always
container_name: auth
image: hanzjk/auth:latest
environment:
- SPRING_PROFILES_ACTIVE=docker
depends_on:
- discovery-server
- api-gateway
## Exhibition-Service Docker Compose Config
exhibition:
platform: linux/amd64
container_name: exhibition
pull_policy: always
image: hanzjk/exhibition:latest
environment:
- SPRING_PROFILES_ACTIVE=docker
depends_on:
- discovery-server
- api-gateway
## Stall-Service Docker Compose Config
stall:
platform: linux/amd64
container_name: stall
pull_policy: always
image: hanzjk/stall:latest
environment:
- SPRING_PROFILES_ACTIVE=docker
depends_on:
- discovery-server
- api-gateway
## Ticket-Service Docker Compose Config
ticket:
platform: linux/amd64
container_name: ticket
pull_policy: always
image: hanzjk/ticket:latest
environment:
- SPRING_PROFILES_ACTIVE=docker
depends_on:
- discovery-server
- api-gateway

Here is the api gateway service configurations,

server.port=8080
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,

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

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

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

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

server.port=8080
eureka.client.serviceUrl.defaultZone=http://eureka:password@discovery-server:8761/eureka
spring.data.mongodb.uri=mongodb+srv://&lt;password&gt;:f702kMP1Mk6nZcGn@nerambum-stats.tpeoaxj.mongodb.net/?retryWrites=true&amp;w=majority
spring.data.mongodb.database=Nerambum-Stats
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时。我遇到了同样的问题,并通过将以下行添加到每个服务的配置文件中解决了它。

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.

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:

确定