title: Docker error resolve host and I/O error on POST request for http://es.example/oauth/check_token Connection refused
body: <p>I've two containers one with AuthServer and another with an api rest/ Resource server.</p>
  
  <p>The flow works with the AuthServer on a container and the ResourceServer in local but when I deploy the Resource server into container shows:</p>
  
  <pre><code> "error": "Internal Server Error",
    "exception": "org.springframework.web.client.ResourceAccessException",
    "message": "I/O error on POST request for \"http://es.example/oauth/check_token\": Connection refused; nested exception is java.net.ConnectException: Connection refused",
  </code></pre>
  
  <p>what am I doing wrong?</p>
  
  <p>NOTE: if I stay into the container ping works :S</p>
  
  <p>Docker files are the same:</p>
  
  <pre><code>FROM xxx.xxx.xxx.xxx:5000/services-base:1.0
  
  EXPOSE 8080
  
  # Services
  ADD build/libs/service-authServer.jar /opt/app.jar
  WORKDIR /opt
  RUN sh -c 'touch app.jar'
  ENTRYPOINT ["java","-Dlogging.config=config/logback.xml","-jar","app.jar"]
  </code></pre>
  
  <p>The image base is an Alpine linux with java 8.</p>
  
  <p>And we deploy in ansible with:</p>
  
  <pre><code>- name: Container is running
    docker:
      image: "{{ registry_url }}/{{ services_oauth2_container }}"
      name: "{{ services_oauth2_name }}"
      ports: "{{ services_oauth2_ports }}"
      hostname: "{{ hostname }}"
      env:
        TZ: "{{ timezone_value }}"
        SERVICE_NAME: "{{ services_oauth2_name }}"
      volumes: "{{ volumes }}"
    tags: [service]
  </code></pre>
  
  <blockquote>
    <p>Dentro del contenedor</p>
  </blockquote>
  
  <pre><code>[root@SERVICES~]# docker exec -it service-rest sh
  /opt # curl -X GET 'http://es.example:2474/api/v1/rest/ping'
  curl: (7) Failed to connect to es.example port 2474: Connection refused
  /opt # curl -X GET 'http://es.example/api/v1/rest/ping'
  curl: (7) Failed to connect to es.example port 80: Connection refused
  /opt # curl -X GET 'http://localhost:8080/api/v1/rest/ping'
  {"timestamp":1467184337030,"status":500,"error":"Internal Server Error","exception":"org.hibernate.exception.GenericJDBCException","message":"could not inspect JDBC autocommit mode","path":"/api/v1/rest"
  /opt # curl -X GET 'http://localhost:8080/me'
  /opt # curl -H 'Authorization: Bearer 76cac1c1-c2e6-4a16-a64c-f347d9e38793' -X GET 'http://localhost:8080/me'
  {"timestamp":1467184455211,"status":500,"error":"Internal Server Error","exception":"org.springframework.web.client.ResourceAccessException","message":"I/O error on POST request for \"http://es.example:2490/oauth/check_token\": Connection refused; nested exception is java.net.ConnectException: Connection refused","path":"/me"}/opt # 
  /opt # 
  /opt # curl -X GET 'http://es.example:2490/oauth/check_token?token=76cac1c1-c2e6-4a16-a64c-f347d9e38793'
  curl: (6) Couldn't resolve host 'es.example'
  /opt # curl -X GET 'http://es.example:2490/oauth/check_token?token=76cac1c1-c2e6-4a16-a64c-f347d9e38793'
  curl: (7) Failed to connect to es.example port 2490: Connection refused
  /opt # curl -X GET 'http://xxx.xxx.xxx.xxx:2490/oauth/check_token?token=76cac1c1-c2e6-4a16-a64c-f347d9e38793'
  {"error":"invalid_token","error_description":"Token has expired"}/opt # ping es.example
  PING es.example (xxx.xxx.xxx.xxx): 56 data bytes
  64 bytes from xxx.xxx.xxx.xxx: seq=0 ttl=64 time=0.085 ms
  64 bytes from xxx.xxx.xxx.xxx: seq=1 ttl=64 time=0.066 ms
  64 bytes from xxx.xxx.xxx.xxx: seq=2 ttl=64 time=0.069 ms
  64 bytes from xxx.xxx.xxx-xxx: seq=3 ttl=64 time=0.060 ms
  ^C
  --- es.example ping statistics ---
  4 packets transmitted, 4 packets received, 0% packet loss
  round-trip min/avg/max = 0.060/0.070/0.085 ms
  /opt # curl -X GET 'http://xxx.xxx.xxx.xxx:2490/oauth/check_token?token=76cac1c1-c2e6-4a16-a64c-f347d9e38793'
  /opt # curl -X GET 'http://xxx.xxx.xxx.xxx:2490/oauth/check_token?token=789cb37b-53b4-4f49-9ae7-c4a7f93c7df5'
  {"exp":1467185199,"user_name":"admin","authorities":["USER","client_id":"clientID","scope":["read","write"]}
  </code></pre>