title: Connection refused with two microservices in Docker
body: <p>I have two microservices and I want that one consumes of the other but I'm obtaining this mistake: </p>
  
  <blockquote>
    <p>Servlet.service() for servlet [dispatcherServlet] in context with path
    [] threw exception [Request processing failed; nested exception is
    org.springframework.web.client.ResourceAccessException: I/O error on
    GET request for "<a href="http://localhost:8080/testMicroservicio" rel="nofollow noreferrer">http://localhost:8080/testMicroservicio</a>": Connection
    refused (Connection refused); nested exception is
    java.net.ConnectException: Connection refused (Connection refused)]
    with root cause</p>
    
    <p>java.net.ConnectException: Connection refused (Connection refused)</p>
  </blockquote>
  
  <p>However if I execute the url in the browser, it works perfectly but if a microservice wants to access to the other microservice, I have this mistake.</p>
  
  <p>Does someone kown why?</p>
  
  <p>I'm consuming with: RestTemplate</p>
  
  <p>I put some of code:</p>
  
  <pre><code>@RestController
  public class MicroServiceController {
  
  
      private final AddressService service;
  
      private static final String URL_API_INFO = "http://localhost:8080/testMicroservicio";
  
      private RestTemplate restTemplate = new RestTemplate();
  
      private final static Logger log = Logger.getLogger("com.bernanetwork.web.controller.MicroServiceController");
  
      @Autowired
      public MicroServiceController(AddressService service) {
          this.service = service;
      }
  
      @RequestMapping(value = "/micro-service-test")
      public String consumidor() throws Exception {
  
          log.info("----------------------------------------------------------------------------------------");
          log.info("-------------------------Iniciando método consumidor------------------------------------");
          log.info("----------------------------------------------------------------------------------------");
  
          ResponseEntity &lt;PruebasMicroservicio[]&gt; response = restTemplate.getForObject(URL_API_INFO, PruebasMicroservicio[].class);
  
          Arrays.asList(response.getBody()).forEach(info -&gt; log.info("---"+info));
  
          return "ok";
      }
  </code></pre>
  
  <p>These microservices are running in Docker</p>
  
  <p>Thanks so much.</p>