无法为官方Mongo泊坞窗图像

时间:2018-04-10 10:48:00

标签: mongodb docker docker-compose

我正在使用docker-compose启动官方mongodb数据库容器。

阅读脚本和一些StackOverflow问题看起来像MONGO_INITDB_环境变量可用于设置默认凭证。

运行以下docker-compose.yml后:

version: '2'
services:
  mongodb:
    image: mongo:3.6
    environment:
      - MONGO_INITDB_ROOT_USERNAME=user
      - MONGO_INITDB_ROOT_PASSWORD=password
      - MONGO_INITDB_DATABASE=collection
    ports:
      - 27017:27017

尝试连接mongo cli或mongoose Node.js ODM我收到身份验证错误:

➔ mongo -u user -p password --verbose localhost:27017/collection
MongoDB shell version: 2.6.10
connecting to: localhost:27017/collection
2018-04-10T12:29:46.386+0200 creating new connection to:localhost:27017
2018-04-10T12:29:46.386+0200 [ConnectBG] BackgroundJob starting: ConnectBG
2018-04-10T12:29:46.387+0200 connected to server localhost:27017 (127.0.0.1)
2018-04-10T12:29:46.387+0200 connected connection!
2018-04-10T12:29:46.391+0200 User Assertion: 18:{ ok: 0.0, errmsg: "auth failed", code: 18, codeName: "AuthenticationFailed" }
2018-04-10T12:29:46.392+0200 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18, codeName: "AuthenticationFailed" } at src/mongo/shell/db.js:1287
2018-04-10T12:29:46.392+0200 User Assertion: 12514:login failed
2018-04-10T12:29:46.393+0200 freeing 1 uncollected N5mongo12DBClientBaseE objects
exception: login failed

连接到入口点脚本[1]中定义的/admin集合给出了相同的结果。我无法看到我做错了什么。

编辑:来自irc.freenode.org #mongodb频道的Derick建议它可能没有选择--auth标志。我试图在没有凭据(mongo --verbose localhost:27017/admin)的情况下登录并且它有效。我仍然遇到建立默认凭据的问题,因此问题尚未解决。

[1] https://github.com/docker-library/mongo/blob/b96fddd1e1a100c01f0ea6d28e1c7ccc750fd5c0/3.6/docker-entrypoint.sh#L292

0 个答案:

没有答案