Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

FROM mcr.microsoft.com/openjdk/jdk:17-ubuntu

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

But when I try to reach 172.17.0.2:8880 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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading