Eugene Shmorgun
Eugene Shmorgun

Reputation: 2075

Why does java app started in Docker container available not on exposed port?

I have Eureka from Spring Cloud started inside docker container. This is my Dockerfile for building and exposing Eureka:

FROM maven:3.5-jdk-8 AS build
COPY src /home/eureka/src
COPY pom.xml /home/eureka
RUN mvn -f /home/eureka/pom.xml clean package

FROM openjdk:8-jdk-alpine
COPY --from=build /home/eureka/target/service-registry-1.0-SNAPSHOT.jar /usr/app/service-registry-1.0-SNAPSHOT.jar

ENTRYPOINT ["java","-jar","/usr/app/service-registry-1.0-SNAPSHOT.jar"]  

EXPOSE 8761

This is my docker compose file:

version: '2.1'

services: 

  eureka-service-registry-app: 
    build: eureka-service-registry-app
    ports:
      - "8761-8761"

There are more app will be in infrastructure, but right now they are commented.

I start docker-compose up, process looks ok, but when I want to check Eureka web dashboard by localhost:8761 this host is unavailable. Hm, ok. In list of my containers I see the follow:

0.0.0.0:32772->8761/tcp

and localhost:32772 is available and Eureka is alive. Moreover if I start docker-compose up again this port will be incremented and new port where Eureka will be available will be 32773. Thus I see there some schema but I don't understand how to make this port stable and regular as Eureka has been started with no Docker on 8761

Upvotes: 0

Views: 1298

Answers (2)

Felix
Felix

Reputation: 135

As others already pointed out: The port exposing in the docker-compose.yml should be changed to -"8761:8761".

However I see more points to that.

The default port of Eureka is (as far as I know) 1111. Are you exposing the correct port?

Furthermore be careful when using eureka in combination with docker. They might register themselves with localhost or their internal IP-Address from the Docker container, which might not be available from the other docker containers.

Consider having a look at the following application proporties (or environment variables):

eureka.instance.prefer-ip-address=false
eureka.instance.ip-address=$HOST_IP_ADDRESS
eureka.instance.hostname=localhost

Upvotes: 0

cmoetzing
cmoetzing

Reputation: 802

You define a port range with

ports:
  - "8761-8761"

Please change it to

ports:
  - "8761:8761"

Upvotes: 3

Related Questions