Docker错误解决POST请求的主机和I / O错误http://es.example/oauth/check_token拒绝连接

时间:2016-06-28 14:09:19

标签: spring networking docker ansible oauth2

我有两个容器,一个用AuthServer,另一个用api rest / Resource服务器。

流程与容器上的AuthServer和本地的ResourceServer一起工作,但是当我将资源服务器部署到容器中时显示:

 "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",

我做错了什么?

注意:如果我留在容器中ping工作:S

Docker文件是相同的:

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"]

图像库是带有java 8的Alpine linux。

我们在ansible部署:

- 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]
  

Dentro del contenedor

[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"]}

1 个答案:

答案 0 :(得分:0)

我在ansible主机名上的配置将容器重定向到自身而不是外部主机。