0

I have created a docker image for deployment of microservice.

I am right now testing ti by trying to deploy on my local machine.

The docker container ogt created successfully and I am getting started application

 o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-10-25 12:41:53.867  INFO [] 1 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed
2019-10-25 12:41:53.901  INFO [] 1 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s)
2019-10-25 12:41:53.949  INFO [] 1 --- [           main] s.d.s.w.s.ApiListingReferenceScanner     : Scanning for api listing references
2019-10-25 12:41:54.230  INFO [] 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''

But when I try to hit any rest service like so localhost:8080/myApi/test
It gives me error

 localhost refused to connect.
Search Google for localhost 8080 payment
ERR_CONNECTION_REFUSED

What could possibly be going wrong ?

Checking list of running images docker ps gives me an entry with empty port details .Could this be the reason ?

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                PORTS               NAMES
2feab85c47db        test_3      "java -Dserver.port=…"   18 minutes ago      Up 18 minutes                             wizardly_leavitt
javaGroup456
  • 313
  • 1
  • 6
  • 21

1 Answers1

1

To access services inside containers you need to forward host ports to container ports.

It can be done with -p HOST_PORT:CONTAINER_PORT parameter in the command line.

docker run -it -p 8080:8080 test_3

REF: https://docs.docker.com/config/containers/container-networking/

  • Using the command worked for me. Could you please explain a bit around this ?Earlier I could not see 8080 port active in the telnet list. – javaGroup456 Oct 25 '19 at 13:17
  • To show port in your docker ps command is to expose them in your Dockerfile (that way you're telling docker that the specified port is expecting connections) or forwarding ports (it'll show all forwarded port list). You can find more about it in this link: https://docs.docker.com/config/containers/container-networking/ – Artur Luiz Oliveira Oct 25 '19 at 13:21