1

I'm running my Docker container and expecting to hit it's endpoints.

In this question, I provided my Dockerfile and gradle.build. How to improve gradle.build file?

The Docker image is built successfully and when I run it I see how Spring Boot is starting including "Spring Boot logo" and Tomcat started on port(s): 9090 (http) with context path ''

I run my image with pavelpolubentcev$ docker run -i -t -e SERVER_PORT=9090 messenger-auth-auth

Nevertheless, I'm not able to access my endpoints, when I try http://localhost:9090 then no "Could not get any response".

When I run docker ps -a I can see my image running:

9d31b3e2aa63 messenger-auth-auth "java -jar /app/mess…" 6 minutes ago Up 6 minutes 8080/tcp practical_nightingale

But for some reason I also see 8080/tcp

What should I do to run it properly and finally get answer from my endpoints?

enter image description here

enter image description here

Thanks for your help, I appreciate it, I really need to solve the issue.

Pasha
  • 1,768
  • 6
  • 22
  • 43
  • you need to publish your ports with `docker run -p 8080:8080` – Ivan Aracki Jan 05 '19 at 21:44
  • Did you make sure you hard-coded the special IP `0.0.0.0` in your Java code or in your `application.properties` file? – ErikMD Jan 05 '19 at 21:44
  • No I didn't hardcode anything – Pasha Jan 05 '19 at 21:44
  • 1
    OK so I suspect your question is a duplicate of [How do I access a spring app running in a docker container?](https://stackoverflow.com/q/52633726/9164010)... anyway, @IvanAracki's comment is also relevant: you need both listening `0.0.0.0` inside the container, and publishing the port with the appropriate option. – ErikMD Jan 05 '19 at 21:46

2 Answers2

2

Map the container port to an external port : docker run -p 9090:9090 ...
The first port is the outside port (which one you want to access now from the host machine) and the second is the inside port (the port on the container). You can specify the same external port or not.

davidxxx
  • 125,838
  • 23
  • 214
  • 215
2

The 8080/tcp you see on output when listing running containers is defined in EXPOSE on the image Dockerfile. But this instruction doesn't actually publish the port.

You have to map your host (machine) port to the container port in order to forward TCP/UDP from host to container.

That said, in your case, the command to run the container is:

docker run -e SERVER_PORT=9090 -p 9090:9090 messenger-auth-auth

bazaglia
  • 633
  • 1
  • 5
  • 20