0

Scenario:

  1. I have a very simple spring boot micro service i.e. video-service with port number defined as 0 (to try the dynamic port assignment by service discovery) and it has a very simple GET /ping method.
  2. There is another service eureka service discovery that is running and detecting the video-service (also showing in eureka dashboard.
  3. Both the services are dockerized, running via docker compose and I did not mention any port number for video-service in Docker-compose.yaml as it does not allow/or showing error when mentioning "0" or "0:0" in compose YAML. I would like to try the option of dynamic port number assignment that is provided by eureka service discovery.
  4. When I mention the static port number in application YAML and compose YAML, video-service /ping REST endpoint is accessible.

Problem

When I try the dynamic port assignment for video-service,/ping REST endpoint is not accessible but it is detected by eureka discovery. Kindly help/suggest me on how to make video-service /ping REST endpoint is accessible with dynamic port assigned by eureka discovery when both the services are containerized/dockerized.

Note:

Mentioning the trimmed version of my code in the below to understand the problem easily.

application.yaml (video-service)

spring:
  application:
    name: "${SPRING_APP_NAME:video-service}"
server:
  port: 0 #9141
eureka:
  client:
    serviceUrl:
      defaultZone: http://eureka-discovery-service:9111/eureka

Compose YAML (Docker compose)

  eureka-discovery-service:
    build:
      context: ./eureka-discovery
    container_name: eureka-discovery-service
    ports:
      - "9111:9111"
    environment:
      - EUREKA_INSTANCE_HOSTNAME=eureka-discovery-service
      - EUREKA_CLIENT_REGISTER-WITH-EUREKA=false
      - EUREKA_INSTANCE_PREFER_IPADDRESS=true

  video-service:
    build:
      context: ./video-service
    container_name: video-service
    depends_on:
      - eureka-discovery-service
#    ports:
#      - "0"
#      - "0:0"
#      - "9141:9141"
    environment:
      - EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://eureka-discovery-service:9111/eureka

Eureka Discovery Service Dashboard

Kindly help/guide me on this as I am new to Spring Cloud.

Thank you in advance.

2
  • Dynamic ports aren't well supported. I suggest not to use it Commented Apr 30 at 12:39
  • @spencergibb - Thank you so much. I will proceed with static port approach. Commented May 1 at 3:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.