Search code examples
dockermicroservices

Docker image ran successfully but application didn't run


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

Solution

  • 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/