瀏覽代碼

Merge pull request #498 from infosiftr/mongo-auth

Add a section about "--auth" to the mongo documentation
yosifkit 9 年之前
父節點
當前提交
62ce870723
共有 1 個文件被更改,包括 35 次插入0 次删除
  1. 35 0
      mongo/content.md

+ 35 - 0
mongo/content.md

@@ -40,6 +40,41 @@ Just add the `--storageEngine` argument if you want to use the WiredTiger storag
 $ docker run --name some-mongo -d mongo --storageEngine wiredTiger
 ```
 
+### Authentication and Authorization
+
+MongoDB does not require authentication by default, but it can be configured to do so. For more details about the functionality described here, please see the sections in the official documentation which describe [authentication](https://docs.mongodb.org/manual/core/authentication/) and [authorization](https://docs.mongodb.org/manual/core/authorization/) in more detail.
+
+#### Start the Database
+
+```console
+$ docker run --name some-mongo -d mongo --auth
+```
+
+#### Add the Initial Admin User
+
+```console
+$ 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"
+		}
+	]
+}
+```
+
+#### Connect Externally
+
+```console
+$ docker run -it --rm --link some-mongo:mongo mongo mongo -u jsmith -p some-initial-password --authenticationDatabase admin some-mongo/some-db
+> db.getName();
+some-db
+```
+
 ## Where to Store Data
 
 Important note: There are several ways to store data used by applications that run in Docker containers. We encourage users of the `%%REPO%%` images to familiarize themselves with the options available, including: