Docker Rails 应用程序 Ruby 的云服务 link
Docker cloud service link for Ruby on Rails application
我正在尝试 docker 云(以前称为 tutum)部署一个 rails 应用程序,该应用程序使用 httparty 从另一个 REST API 获取数据(也部署在 docker 云)。因此,代码将类似于以下内容:
def get_service_response
response = HTTParty.get("#{api_service_url}/foo/]"
end
def self.api_service_url
ENV['SERVICE_URL']
end
我们是 运行 两个 HAProxies,一个用于 rails 网络,另一个用于 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 调用的服务 link。
要覆盖Httparty
中的base_uri
(在我们的例子中是Nil
),我们需要以http://
或[=15开始查询路径=].我们通过如下设置 env 变量来解决上述问题:
environment:
SERVICE_URL: http://haproxy-service
我正在尝试 docker 云(以前称为 tutum)部署一个 rails 应用程序,该应用程序使用 httparty 从另一个 REST API 获取数据(也部署在 docker 云)。因此,代码将类似于以下内容:
def get_service_response
response = HTTParty.get("#{api_service_url}/foo/]"
end
def self.api_service_url
ENV['SERVICE_URL']
end
我们是 运行 两个 HAProxies,一个用于 rails 网络,另一个用于 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 调用的服务 link。
要覆盖Httparty
中的base_uri
(在我们的例子中是Nil
),我们需要以http://
或[=15开始查询路径=].我们通过如下设置 env 变量来解决上述问题:
environment:
SERVICE_URL: http://haproxy-service