[英]How can I make a HTTP request from one docker container to another linked container?
I have a docker container with an sinatra app inside, and another container with an node.js app. 我有一个带有sinatra应用程序的docker容器,另一个带有node.js应用程序的容器。 They are both linked through Fig. In my sinatra app I am making a HTTP Post request to the node.js app.
它们都通过图链接。在我的sinatra应用程序中,我正在向node.js应用程序发出HTTP Post请求。 For that I am using the Faraday gem.
为此,我使用法拉第宝石。
My questions is now how can I make a HTTP request to another linked container. 我现在的问题是如何向另一个链接容器发出HTTP请求。
Here's my fig.yml 这是我的fig.yml
db:
image: mongo:2.6.7
command: --smallfiles
api:
build: ./api
command: bundle exec rackup -p 3000
volumes:
- ./api:/code
ports:
- "3000:3000"
links:
- db
- flickrcrawler
flickrcrawler:
build: ./flickr-crawler
ports:
- "3100:3100"
links:
- db
and here's the method in the sinatra app I use to make a HTTP request with farady: 这是我用sinradra应用程序用farady发出HTTP请求的方法:
def crawler_call(url, tags)
tags.each do |t|
conn = Faraday.new(url: url) do |faraday|
faraday.request :url_encoded
faraday.response :logger
faraday.adapter Faraday.default_adapter
end
conn.post "#{t}"
end
end
what would I pass this method as url parameter? 我将这个方法作为url参数传递给我什么?
You would use the name of the service in your fig.yml
, in this case I think you're calling it flickrcrawler
. 您可以在
fig.yml
使用该服务的名称,在这种情况下,我认为您将其flickrcrawler
。 So something like http://flickrcrawler:3100
. 所以像
http://flickrcrawler:3100
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.