【发布时间】:2018-11-12 20:58:36
【问题描述】:
我正在尝试通过多个Rails node + docker + MySQL + Redis来做多个节点分发系统。
因此,我的主节点需要与其他节点通信。
这是我的 docker-compose.yml
**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 && 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 && 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 && 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"**
但是,当我尝试使用app 节点向pub_node 发送请求时,它抛出了这个错误。
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'
我通过这段代码在做post。
rvlist = '127.0.0.1:4000'
HTTParty.post("http://#{rvlist}/publish", options)
它可以在没有 docker 环境的情况下在我的开发模式下工作。
【问题讨论】:
-
你可以试试
POST和rvlist = 'pub_node:4000'吗? -
是的!!!有用!!请您回答这个问题并留下一些文件或参考资料好吗?我会选择你作为答案!
标签: ruby-on-rails docker docker-compose