1

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.

Albert
  • 13
  • 3
  • Have a look here: https://stackoverflow.com/questions/52003431/docker-for-windows-access-container-in-local-network/52003606#52003606 Maybe you have to pass the port to the container. – Hannes Jan 22 '19 at 06:54
  • What's your operating system? – Pijotrek Jan 22 '19 at 06:55
  • did you run like this `docker run -p 9090:9090` ? that mean map port `9090` inside container to `9090` on host machine – Truong Dang Jan 22 '19 at 06:55
  • 1. My operation system is Win 10. – Albert Jan 22 '19 at 07:04
  • 2. I tried do like this : docker run -d -p 9090:9090 47ab55bdf5b7 It didn't help me. C:\Users\gazinaa>docker run -d -p 9090:9090 47ab55bdf5b7 2dac0a50d8a528e5895075f22498604af9bcf58fd212d3a11286aa59c824803a But image doesn't start on this port. – Albert Jan 22 '19 at 07:04
  • 3. When I put the command docker run among the messages I see : 2019-01-22 06:57:19.719 INFO [-,,,] 1 --- [-server-epoll-5] r.ipc.netty.tcp.BlockingNettyContext : Started HttpServer on /0.0.0.0:8080 2019-01-22 06:57:19.719 INFO [-,,,] 1 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port(s): 8080 Maybe I must change the port of this NettyWebServer ? How can I do it ? – Albert Jan 22 '19 at 07:04

1 Answers1

1

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.

Pijotrek
  • 2,821
  • 1
  • 18
  • 32