title: Rails send request to other container [Failed to open TCP connection]
body: <p>I am trying to do multiple node distribution systems by multiple <code>Rails node + docker + MySQL + Redis</code>.</p>
  
  <p>Therefore, my main node needs to communicate with other nodes.</p>
  
  <p>Here is my <strong>docker-compose.yml</strong></p>
  
  <pre><code>**version: '2'
  services:
    db:
      image: mysql:5.7
      restart: always
      environment:
        - MYSQL_ROOT_PASSWORD=password
        - MYSQL_DATABASE=pubsub_1_development
        - MYSQL_USER=appuser
        - MYSQL_PASSWORD=password
      ports:
        - "3308:3306"
  
    redis:
      image: 'redis:4.0-alpine'
  
    app:
      image: pubsub_2:1.0.8
      command: /bin/sh -c "rm -f ./tmp/pids/server.pid &amp;&amp; bundle exec rails s -p 3000 -b '0.0.0.0'"
      volumes:
        - ".:/pubsub_2"
      ports:
        - "3001:3000"
      depends_on:
        - db
        - redis
        - sub_node
        - pub_node
      links:
        - db
        - redis
        - sub_node
        - pub_node
      environment:
        DB_USER: root
        DB_NAME: pubsub_1_development
        DB_PASSWORD: password
        DB_HOST: db
        REDIS_CABLE_PORT: redis://redis:6379/1
        SUB_NODE: 0.0.0.0:4001
        PUB_NODE: 0.0.0.0:4000
      stdin_open: true
      tty: true
  
    sub_node:
      image: sub_node:1.0.1
      command: /bin/sh -c "rm -f /sub_node/tmp/pids/server.pid &amp;&amp; bundle exec rails s -p 4001 -b '0.0.0.0'"
      ports:
        - "4001:4001"
      environment:
        DB_USER: root
        DB_NAME: pubsub_1_development
        DB_PASSWORD: password
        DB_HOST: db
        REDIS_CABLE_PORT: redis://redis:6379/1
      tty: true
      expose:
        - "4001"
  
  
    pub_node:
      image: pub_node:1.0.1
      command: /bin/sh -c "rm -f /pub_node/tmp/pids/server.pid &amp;&amp; bundle exec rails s -p 4000 -b '0.0.0.0'"
      ports:
        - "4000:4000"
      environment:
        DB_USER: root
        DB_NAME: pubsub_1_development
        DB_PASSWORD: password
        DB_HOST: db
        REDIS_CABLE_PORT: redis://redis:6379/1
      tty: true
      expose:
        - "4000"**
  </code></pre>
  
  <p>However, when I try to use <code>app</code> node to send the request to <code>pub_node</code>, it threw this error.</p>
  
  <pre><code>Errno::ECONNREFUSED: Failed to open TCP connection to 127.0.0.1:4000 (Connection refused - connect(2) for "127.0.0.1" port 4000)
  from /usr/local/lib/ruby/2.5.0/net/http.rb:939:in `rescue in block in connect'
  </code></pre>
  
  <p>I was doing <code>post</code> by this code.</p>
  
  <pre><code>rvlist = '127.0.0.1:4000'
  HTTParty.post("http://#{rvlist}/publish", options)
  </code></pre>
  
  <p>It works in my development mode without the docker environment.</p>