繁体   English   中英

Docker内部mongo中的shell命令无法通过身份验证

[英]shell commands in mongo inside Docker fails for Authentication

我试图在docker容器内的mongo中运行一些shell命令。

docker exec -it mongodb_mock  bash

它打开mongo外壳。 但是当我在其中运行任何命令时,它会给出身份验证错误:

    > show dbs
2018-08-28T10:12:12.755+0000 E QUERY    [thread1] Error: listDatabases failed:{
    "ok" : 0,
    "errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
    "code" : 13,
    "codeName" : "Unauthorized"
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:62:1
shellHelper.show@src/mongo/shell/utils.js:781:19
shellHelper@src/mongo/shell/utils.js:671:15
@(shellhelp2):1:1

请帮忙。

编辑:此数据库是通过猫鼬/ express从另一个容器创建的。

首先,您需要使用用户授权数据库,以下是示例命令

use admin;
db.auth('admin','password');

然后您便可以运行所有查询。 或在不使用--auth参数的情况下启动mongod,因此您不需要用户身份验证。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM