2016-03-05 79 views
0

我正在尝试docker云(以前是tutum)部署一个使用httparty从另一个REST API(也部署在docker云中)获取数据的rails应用程序。因此,该代码将类似如下:Ruby on Rails应用程序的Docker云服务链接

def get_service_response 
    response = HTTParty.get("#{api_service_url}/foo/]" 
end 

def self.api_service_url 
    ENV['SERVICE_URL'] 
end 

我们正在运行的两个HAProxies,一个用于轨道网络和其他的REST API。因此,Stackfile看起来象下面这样:

web: 
image: organization/web-image 
    ports: 
    - "3000:3000" 
    tags: 
    - deploy_tag 
    links: 
    - haproxy-service 
    environment: 
    SERVICE_URL: haproxy-service 

service: 
    image: organization/service-image 
    ports: 
    - "8080:8080" 
    tags: 
    - deploy_tag 

haproxy-web: 
    image: 'dockercloud/haproxy:latest' 
    environment: 
    - BACKEND_PORT=3000 
    - BALANCE=roundrobin 
    links: 
    - web 
    ports: 
    - '80:80' 
    tags: 
    - deploy_tag 

haproxy-service: 
    image: 'dockercloud/haproxy:latest' 
    environment: 
    - BACKEND_PORT=8080 
    - BALANCE=roundrobin 
    links: 
    - service 
    ports: 
    - "8000:8000" 
    tags: 
    - deploy_tag 

但是,我get_service_response方法与下面的错误而失败:

Errno::ECONNREFUSED (Failed to open TCP connection to :80 (Connection refused - connect(2) for nil port 80)): 

当我试图从终端的Web容器卷曲,我能够看到从服务

echo $SERVICE_URL 
# displays haproxy-service 
curl $SERVICE_URL/foo 
#I see the expected response 

我想知道的响应,为什么Rails应用程序是无法评估从httparty呼叫服务链接。

回答

0

要覆盖在Httpartybase_uri(在我们的情况下,它是Nil),我们需要开始查询作为http://https://的路径。我们通过如下设置我们的env变量来解决上述问题:

environment: 
    SERVICE_URL: http://haproxy-service