I'm trying to run my spring apps in containers,
atm, I have 2 containers, 1 running my Spring Config Server, running in port 8888, if I open a browser I do get the properties, no problem there(I think),
the second container is Spring Eureka Discovery Server, running on port 8787, but when I build the project in maven, then build the image, and run it, I get these errors in the log:
2025-04-07 12:03:56 2025-04-07T18:03:56.388Z INFO 1 --- [app-seven-eureka] [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://10.1.10.220:8888
2025-04-07 12:03:59 2025-04-07T18:03:59.853Z INFO 1 --- [app-seven-eureka] [ main] c.c.c.ConfigServicePropertySourceLocator : Exception on Url - http://10.1.10.220:8888:org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://10.1.10.220:8888/app-seven-eureka/default": No route to host. Will be trying the next url if available
2025-04-07 12:03:59 2025-04-07T18:03:59.853Z WARN 1 --- [app-seven-eureka] [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://10.1.10.220:8888/app-seven-eureka/default": No route to host
2025-04-07 12:03:59 2025-04-07T18:03:59.857Z INFO 1 --- [app-seven-eureka] [ main] .s.AppMSEurekaApplication : No active profile set, falling back to 1 default profile: "default"
and the application doesn't respond and some other errors are thrown, and as I cant see, those are because it is not loading the configuration parameters from the config server...
starting the second application from Eclipse or running the jar in the terminal throws no error, server starts up alright and responds in the right port, it is when is inside the container,
this is my dockerfile:
FROM openjdk:25-oraclelinux8
WORKDIR /app
COPY target/app-seven-eureka-1.0.0.jar /app/app7.jar
EXPOSE 8787
ENTRYPOINT ["java", "-jar", "/app/app7.jar"]
I did change my application.properties to bootstrap.properties as recommended in this question, but without effect: Spring Cloud Config Client: Fetching config from wrong server
My command to run the container is: docker run -p 8787:8787 app-seven-eureka
So, am I missing something? do I have to pass an additional parameter when I create the container? or what could be the problem?
Solution:
Switched to docker composer to create the containers and created a network between them:
services:
service-config:
container_name: app-seven-config
networks:
- app-seven-network
service-eureka:
container_name: app-seven-eureka
networks:
- app-seven-network
extra_hosts:
- "docker.internal:127.0.0.1"
networks:
app-seven-network:
driver: bridge
Do your containers share the same network? Looking at the run command you provided the answer is probably not.
From the docker documentation https://docs.docker.com/engine/network/
If you want to make a container accessible to other containers, it isn't necessary to publish the container's ports. You can enable inter-container communication by connecting the containers to the same network, usually a bridge network.
Having that, you would want to create a network first, and then run your containers
docker network create -d bridge my-net
docker run --network=my-net app-seven-eureka
Alternatively you can use docker compose for your containers management