如何在docker-entrypoint-init.d的脚本上进行身份验证

时间:2018-10-08 11:01:12

标签: javascript mongodb docker docker-compose

我想使用docker-compose在MongoDB上创建用户。 我可以使用docker-compose环境属性创建MONGO_INITDB_ROOT_USER。

并且MONGO_INITDB_ROOT_USER有权使用密码连接到管理员。

但是,我无法运行用于在docker-entrypoint-initdb.d中为新数据库创建新用户的脚本,并且docker-compose日志在下面。

mongodb    | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/0-user.js
mongodb    | 2018-10-08T10:16:20.696+0000 I NETWORK  [listener] connection accepted from 127.0.0.1:45976 #3 (1 connection now open)
mongodb    | 2018-10-08T10:16:20.697+0000 I NETWORK  [conn3] received client metadata from 127.0.0.1:45976 conn3: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.6.8" }, os: { type: "Linux", name: "PRETTY_NAME="Debian GNU/Linux 9 (stretch)"", architecture: "x86_64", version: "Kernel 4.15.0-1022-azure" } }
mongodb    | 2018-10-08T10:16:20.699+0000 I ACCESS   [conn3] Unauthorized: not authorized on admin to execute command { usersInfo: 1.0, $db: "admin" }                                       
mongodb    | 2018-10-08T10:16:20.699+0000 E QUERY    [thread1] Error: not authorized on admin to execute command { usersInfo: 1.0, $db: "admin" } :
mongodb    | _getErrorWithCode@src/mongo/shell/utils.js:25:13
mongodb    | DB.prototype.getUsers@src/mongo/shell/db.js:1686:1                                                                                                                              
mongodb    | @/docker-entrypoint-initdb.d/0-user.js:17:20
mongodb    | failed to load: /docker-entrypoint-initdb.d/0-user.js                                                                                                                           
mongodb    | 2018-10-08T10:16:20.700+0000 I NETWORK  [conn3] end connection 127.0.0.1:45976 (0 connections now open)

如何从docker-entrypoint-initdb.d的脚本中授权对管理员执行命令?

0 个答案:

没有答案