Cannot reach Spring boot application in Docker

I have a Eureka Discovery Service build with Spring Boot 3.
I created Dockerfile file with following content:


RUN addgroup --system spring
RUN adduser --system spring
USER spring:spring
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
EXPOSE 8880:8880

When I do docker ps I could see the app:

$ docker ps
CONTAINER ID   IMAGE          COMMAND                CREATED          STATUS          PORTS      NAMES
e80974c83e6c   7bb35c99e929   "java -jar /app.jar"   51 seconds ago   Up 50 seconds   8880/tcp   magical_lichterman

Docker inspect returns me following IP address of container

docker inspect   -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' e80974c83e6c

But when I try to reach then I got ERR_CONNECTION_TIMED_OUT. Any Ideas what could be wrong?

>Solution :

It depends where is the request comes from.

  • If you try from a different container, make sure they are on the same network.
docker network create my-network
docker run --name spring-app -d --network my-network <your_image> # your spring container
docker run -d --network my-network <your_other_image> # should make a request to "http://spring-app:8080"
  • If you try to access from the host you should open the container port
docker run -d -p 8080:8080 <your_image>

Then try running curl http://localhost:8080.

Leave a Reply