我正在计算机上运行 mongodb docker容器,我想在启动计算机时启动它。但是,每次启动计算机时,我都必须对容器进行docker restart
操作,因为当我向其提供有效凭据时,“自动启动”容器会用Authentication failed
拍打我。手动重新启动有问题的容器可立即解决问题。
我正在加密分区上使用最新的docker 和 MongoDB 4.0.2 运行 Ubuntu 18.04 系统。 / strong>(虽然我尝试过的每个版本都遇到了这个问题)。奇怪的是,在未加密的分区上不会发生此问题。
我想知道这是否possibly
是由分区的加密引起的(在Ubuntu安装过程中,您可以选择加密)。此外,我对这个问题深感兴趣,对此的任何镜头都值得赞赏。最后,我不确定在哪里打开错误报告,是否是mongo,docker,Ubuntu或Ubuntu使用的加密问题。
如果有人想复制问题:
启动一个不安全的mongo容器。
docker run --volume ~/test-data:/data/db --publish --name mongo-unauthenticated 27017:27017 mongo:4.0.2
连接到它并创建一些用户:
mongo
use admin
db.createUser(
{
user: "admin",
pwd: "password",
roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
}
)
use test
db.createUser(
{
user: "tester",
pwd: "password",
roles: [ { role: "readWrite", db: "test" } ]
}
)
exit
现在使不安全的mongo脱机:
docker stop mongo-unauthenticated
并放置安全版本。请注意导致容器自动启动的--restart always
标志。
docker run --restart always --publish 27017:27017 --name test-mongo -v ~/test-data:/data/db mongo:4.0.2 --auth
检查您是否可以使用有效的凭据进行连接:
mongo --port 27017 -u "tester" -p "password" --authenticationDatabase "test"
彻底关机:
docker stop mongo-unauthenticated
重新启动计算机。
reboot
检查--restart always
是否有效。
docker ps
使用原始凭据使身份验证失败。
mongo --port 27017 -u "tester" -p "password" --authenticationDatabase "test"