Docker Community Forums

Share and learn in the Docker community.

Docker-compose how to make services speak together


(Negw) #1

Hi, I have to services that must speak together, mostly using OAUTH, but also through normal HTTP calls.

This, I believe, is the relevant bit:

  directory:
    build: ./directory
    command: bundle exec puma -C config/puma.rb
    ports: 
      - 2120:3000
    environment:
      - RAILS_LOG_TO_STDOUT=1
      - SPEC_URL=http://localhost:2121
      - TENDER_URL=http://localhost:2121
      - TENDER_SERVICE=http://tender:2121

  tender:
    build: ./tender
    command: bundle exec puma -C config/puma.rb
    ports:
      - 2121:3000
    environment:
      - RAILS_LOG_TO_STDOUT=1
      - DIRECTORY_URL=http://localhost:2120
      - SPEC_URL=http://localhost:2121
      - TENDER_URL=http://localhost:2121

You can see my first “problem”, which maybe is not a problem at all, but still I wanted if possible some suggestions: OAUTH works by redirecting the browser, which means localhost, HTTP calls between services are through docker, hence the http://tender:2121
It’s really the same service in the same container, the only thing that changes is the context. Is there a way to improve this?
And, it doesn’t really work, I make an http request to TENDER_SERVICE and it crashes with:

Errno::ECONNREFUSED (Failed to open TCP connection to tender:2121 (Connection refused - connect(2) for “tender” port 2121))

How can I fix this? All services are running apparently correctly, and I can open with my browser localhost:2121.

TIA,
ngw