简体   繁体   中英

Authenticating into Mongodb docker container

How to use authentication in Mongodb docker container? Create user and use that user authentication in Mongodb containers

While using Mongodb and Python flask application, we want to secure mongodb container with perticular username and password.

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. 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"
        }
    ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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