I have a problem with my Spring Boot Application running in Docker.
Here is my Dockerfile embedded in my app shown below.
FROM adoptopenjdk:11-jre-hotspot
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java","-jar","/app-0.0.1-SNAPSHOT.jar"]
After I run mvn clean install
, I get an app-0.0.1-SNAPSHOT.jar and then define it into a Docker file
Next, I ran this command docker build -t app .
I saw this container installed on my docker desktop.
After running this command docker image ls
, I also saw this container in the list.
I ran this command docker run -p 9999:8080 app
to run it in docker.
The container worked flawlessly after running this command (docker ps
)
Next, I test any URL like http://localhost:9999/getCategoryById/1
instead of http://localhost:8080/getCategoryById/1
in Postman but I get the message (Could not send request). When I test this URL in the browser, I get the message ERR_EMPTY_RESPONSE.
I learned the container IP address via docker inspect container_id
then I used http://172.17.0.2:9999/getCategoryById/1
but nothing changed.
I also checked if the IP address manages the package (ping 172.17.0.2) but I got Request timed out
message.
Here is my project link : Link
How can I fix my issue?
CodePudding user response:
In your application, server.port
property in application.properties
file, that's used to configure port for Spring Boot embedded Tomcat Server is 8082
.
To access the application on the container port 8080
, you'd need to override server.port
property. One of the ways property can be overridden is using an environment variable like below,
docker run -e SERVER_PORT=8080 -p 9999:8080 app
where SERVER_PORT corresponds to the container port specified in -p <hostPort>:<containerPort>
Other option is to directly update the property in application.properties
file like below. After the update, you can then use the same command you've used to run the docker image docker run -p 9999:8080 app
server.port= 8080