简体   繁体   English

向Mongodb Docker容器进行身份验证

[英]Authenticating into Mongodb docker container

How to use authentication in Mongodb docker container? 如何在Mongodb Docker容器中使用身份验证? Create user and use that user authentication in Mongodb containers 创建用户并在Mongodb容器中使用该用户身份验证

While using Mongodb and Python flask application, we want to secure mongodb container with perticular username and password. 在使用Mongodb和Python flask应用程序时,我们要使用特定的用户名和密码来保护mongodb容器。

As written in the documentation on docker hub , you need to run the image with the --auth flag, and then add the initial admin user. 就像--auth hub上的文档中所写的那样,您需要使用--auth标志运行映像,然后添加初始admin用户。 Summary of the steps: 步骤摘要:

Start the Database 启动数据库

docker run --name some-mongo -d mongo --auth

Add the Initial Admin User 添加初始管理员用户

$ docker exec -it some-mongo mongo admin
connecting to: admin
> db.createUser({ user: 'jsmith', pwd: 'some-initial-password', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] });
Successfully added user: {
    "user" : "jsmith",
    "roles" : [
        {
            "role" : "userAdminAnyDatabase",
            "db" : "admin"
        }
    ]
}

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

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