Docker无法连接到副本集的主节点#<Moped :: Cluster:69840575665060 @seeds = >

我有两个容器。 第一个容器有独angular兽,第二个容器有mongod。

Name Command State Ports ------------------------------------------------------------------------------------- app_mongodb_1 /entrypoint.sh mongod Up 0.0.0.0:27017->27017/tcp app_web_1 foreman start Up 0.0.0.0:3000->3000/tcp 

当我尝试访问我的rails应用程序返回错误not connect to a primary node for replica set #<Moped::Cluster:69840575665060 @seeds=[<Moped::Node resolved_address="127.0.0.1:27017">]> ,但当我inputdocker-compose web run rails c我可以保存文件: f = Feature.new(name: "test", value: 10) => #<Feature _id: 565deac0616e642856000000, name: "test", value: 10, created_at: nil, updated_at: nil> => f.save => true

configuration/ mongodb.yml

 development: sessions: default: database: app_development hosts: - mongodb options: options: test: sessions: default: database: app_test hosts: - mongodb options: read: primary max_retries: 1 retry_interval: 0 production: sessions: default: database: app_production hosts: - mongodb options: read: primary max_retries: 1 retry_interval: 0 

我不明白,这是错误是在127.0.0.1 ,但在configuration文件中我没有定义这个地址。

/ etc / hosts文件

 172.17.0.3 mongodb 49ea2c077967 app_mongodb