mongodb - Docker 内 mongo 中的 shell 命令无法进行身份验证
问题描述
我正在尝试在 docker 容器内的 mongo 中运行一些 shell 命令。
docker exec -it mongodb_mock bash
它打开了 mongo shell。但是当我在其中运行任何命令时,它会给出身份验证错误:
> 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
请帮忙。
编辑:这个数据库是通过猫鼬/快递从另一个容器创建的。
解决方案
first you need to authorize db with user, below is example command
use admin;
db.auth('admin','password');
then your able to run all querys. or start mongod without --auth parameter so you no need user authentication.