Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. They are both linked through Fig. In my sinatra app I am making a HTTP Post request to the node.js app. For that I am using the Faraday gem.

My questions is now how can I make a HTTP request to another linked container.

Here's my 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:

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?

like image 834
Markus Török Avatar asked Dec 02 '25 15:12

Markus Török


1 Answers

You would use the name of the service in your fig.yml, in this case I think you're calling it flickrcrawler. So something like http://flickrcrawler:3100.

like image 101
Abdullah Jibaly Avatar answered Dec 05 '25 04:12

Abdullah Jibaly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!