docker-composemicroservicesnetflix-eurekahttp-status-code-413

Docker compose not letting access to services


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: '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

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://<password>:f702kMP1Mk6nZcGn@nerambum-stats.tpeoaxj.mongodb.net/?retryWrites=true&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.


Solution

  • 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.