【问题标题】:Mongodb official image errno:111 Connection refused when trying to create replicasetMongodb 官方镜像 errno:111 Connection refused when trying to create replicaset
【发布时间】:2016-09-04 06:58:15
【问题描述】:

我正在尝试使用官方 MongoDB docker 映像在单个容器内创建一个 3 组复制集群。

按照this官方指南,我创建了以下dockerfile:

  FROM mongo:3.2
    RUN mkdir -p /srv/mongodb/rs0-0 /srv/mongodb/rs0-1 /srv/mongodb/rs0-2
    CMD mongod --port 27017 --dbpath /srv/mongodb/rs0-0 --replSet rs0 --smallfiles --oplogSize 128 &
    CMD mongod --port 27018 --dbpath /srv/mongodb/rs0-1 --replSet rs0 --smallfiles --oplogSize 128 &
    CMD mongod --port 27019 --dbpath /srv/mongodb/rs0-2 --replSet rs0 --smallfiles --oplogSize 128 &
    CMD mongo --port 27017 --eval 'rs.initiate({_id: "rs0",members: [{_id: 0,host: "localhost:27017"}]})'
    CMD mongo --port 27017 --eval "printjson(rs.conf())"
    CMD mongo --port 27017 --eval 'rs.add("localhost:27018")'
    CMD mongo --port 27017 --eval 'rs.add("localhost:27019")'
    CMD mongo --port 27017 --eval "printjson(rs.status())"

但是当我运行它时,我得到以下错误:

  MongoDB shell version: 3.2.9
    connecting to: 127.0.0.1:27017/test
    2016-09-04T06:53:06.664+0000 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
    2016-09-04T06:53:06.664+0000 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
    connect@src/mongo/shell/mongo.js:231:14
    @(connect):1:6
    exception: connect failed

当我运行原始 mongo 映像并尝试运行相同的 CMD 时,我得到的结果不一样。

我尝试将 USER root 添加到 Dockerfile 中,但这根本没有帮助。

我可以做些什么来完成这项工作?

更新

  • 还尝试从ubuntu开始创建图像,结果相同
  • 嗯,这似乎是某种 docker 文件权限问题。当我将代码移动到 bash 脚本并从那里运行时,一切正常。这不是为什么会发生这种情况的答案,而是您需要时的解决方案。

【问题讨论】:

    标签: mongodb docker mongodb-replica-set


    【解决方案1】:

    您的 dockerfile 无法正常工作,因为您输入了多个 CMD,这是无效的。

    documentation 说:

    一个 Dockerfile 中只能有一个 CMD 指令。如果你列出了多个 CMD,那么只有最后一个 CMD 会生效。

    【讨论】:

      猜你喜欢
      • 2011-08-22
      • 1970-01-01
      • 2017-07-30
      • 2021-10-03
      • 2016-01-21
      • 2020-07-09
      • 2021-09-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多