title: Docker : java.net.ConnectException: Connection refused - Application running at port 8083 is not able to access other application on port 3000
body: <p>I have to consume an external rest API(using restTemplate.exchange) with Spring Boot. My rest API is running on port 8083 with URL <a href="http://localhost:8083/myrest" rel="nofollow noreferrer">http://localhost:8083/myrest</a> (Docker command : <code>docker run -p 8083:8083 myrest-app</code>)</p>
  
  <p>External API is available in form of public docker image and after running below command , I am able to pull and run it locally.</p>
  
  <pre><code> docker pull dockerExternalId/external-rest-api docker
      run -d -p 3000:3000 dockerExternalId/external-rest-api
  </code></pre>
  
  <p>a) If I enter external rest API URL, for example <a href="http://localhost:3000/externalrestapi/testresource" rel="nofollow noreferrer">http://localhost:3000/externalrestapi/testresource</a> directly in chrome, then I get valid JSON data.</p>
  
  <p>b) If I invoke it with myrest application from eclipse(Spring Boot Application), still I am getting valid JSON Response. (I am using Windows Platform to test this)</p>
  
  <p>c) But if I run it on Docker and execute myrest service (say <a href="http://localhost:8083/myrest" rel="nofollow noreferrer">http://localhost:8083/myrest</a>), then i am facing <code>java.net.ConnectException: Connection refused</code> </p>
  
  <p><strong>More details :</strong> </p>
  
  <pre><code>org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:3000/externalrestapi/testresource": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
  </code></pre>
  
  <p><strong>P.S -  I am using Docker on Windows.</strong></p>