Skip to content
Advertisement

Spring Boot application cannot run in Docker

I am building a Spring Boot application for providing some REST services and I’d like to import it in Docker. If I run my application within IntelliJ pressing the run button, I can load the endpoints correctly.

My app is listening on the port 8091, as my dockerfile is the following

FROM openjdk:11
ADD out/artifacts/web_services_main_jar/web_services.main.jar lib_image.jar
EXPOSE 8091
ENTRYPOINT ["java","-jar","lib_image.jar"]

The code for building and running the docker container is the following

docker build --build-arg JAR_FILE=out/artifacts/web_services_main_jar/web_services.main.jar -t lib_proj .

docker run -p 8090:8091 lib_proj

The problem is that when the application is running in docker and I try to load “localhost:8090/user” in a browser, chrome returns the ERR_EMPTY_RESPONSE message.

If I open Docker and open the CLI of the container and I run

curl localhost:8091/user

even here an error is printed “curl: (7) Failed to connect to localhost port 8091: Connection refused”. Any suggestion?

EDIT: my application.properties already specifies address and port as follows:

server.address=0.0.0.0
server.port=8091

Advertisement

Answer

Ok a workaround I found is to leave all the port to the default 8080. So i replaced the 8091 in the dockerfile and the 8090 in the “docker run …” command to 8080 and now it works here. I assume because tomcat behind the scene only listens to this one, and I’m figuring out how to change this.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement