I created a sample web-app in Java (with using Gradle and SpringBoot) and then dockerized it with Jib. In my build.gradle file there is a row : "ports = ['9090']" because I want to see web-app on this port. And in my application.properties file there is a row : "server.port=9090".
Docker Image succesfully created. But when I run this image I couldn't see results of its working. If I run jar file everything is OK. Web-app works on 9090 port.
I want to see my web-app working, when I execute command docker run . How can I change the port of the image or of anything else ( NettyWebServer properties ) to see the running image on that port what I want ? Can you help me with this issue please ? Thank You.
If you want a different port in your docker image than on your local environment u can copy different application.properties
file with server.port=XXXX
specified using this command in your Dockerfile
COPY ./src/main/resources/docker-application.properties /opt/my-app/docker-application.properties
Then in your entrypoint.sh
java -jar /opt/my-app/my-app-0.0.1-SNAPSHOT.jar --spring.config.location=/opt/my-app/docker-application.properties
After building the app with your tool (be maven or gradle) you need to run following commands (assuming you are in the app directory with your Dockerfile
etc)
docker build -t my-app .
docker run -d -p [desired_port]:[docker_application_properties_port] --name my-app my-app
The desired_port
is the port you will put in the URL. The docker_application_properties_port
is the one you specified in your docker-application.properties
file.
If you are running Windows OS
then a lot of users make a mistake trying to use 127.0.0.1:9090
. You should try using 192.168.99.100:9090
and if it doesn't work then you need to run CMD
and then ipconfig /all
and look for something like Ethernet Adapter (DockerNAT)
and see the IP
there.