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?

2
  • Yeah I knew it had to be related to the port! But I wasn't sure how it all had to be configured together... Commented Oct 3, 2021 at 15:47
  • Things happen, it's fine to be wrong. However, try to research the topic first before asking! Commented Oct 3, 2021 at 15:55

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.