0

I have built a RESTful Web Service using with Spring (Maven) referring to this guide and it works great:

https://spring.io/guides/gs/rest-service/

Now I wanted to launch this in a container using Docker and I'm hitting the issue. See below my Dockerfile:

#Take the base Java image to build upon
FROM openjdk:11
#Expose the container port that your application listens to outside world
#In the Sample application you can find this under Application.properties
EXPOSE 9090
#Add our application Jar file to the package
ADD target/demo-0.0.1-SNAPSHOT.jar demo.jar
# Run the application
ENTRYPOINT ["java", "-jar", "demo.jar"]

I build and run this using commands:

docker build -t username/demo.jar .
docker run -p 80:9090 username/demo.jar

I checked the application.properties file and it is empty. I dunno if something needs to be set here.

How can I correct this?

1 Answers1

1

From checking different posts and blogs online, the issue was to do with the port. By default, Spring will use 8080. When I changed it from 9090 in both the Dockerfile and command, it worked.

I found a blog that shows different ways to change it but I haven't tried it out:

https://www.baeldung.com/spring-boot-change-port