简体   繁体   English

Mongo docker 映像不持久化用户创建

[英]Mongo docker image not persisting user creation

I am trying to build my own mongo docker image.我正在尝试构建自己的 mongo docker 映像。 After installing mongo in the build process, I also want to add few pre-seeded users.在构建过程中安装 mongo 后,我还想添加一些预种子用户。

db = db = db.getSiblingDB("<dbname>");

db.createUser(
   {
     user: "<username>",
     pwd: "<password>",
     roles: [ { role: "readWrite", db: "<dbname>" } ]
   }
)

Once the image is built , I spin up a container and "use" correct db , I do not see the users created --构建图像后,我启动一个容器并“使用”正确的 db,我没有看到创建的用户 -

db.getUsers() [ ] db.getUsers() [ ]

I have read the article here , which suggests to create ephemeral containers but does not necessary claim that they are indeed ephemeral.我读过这里的文章,它建议创建临时容器,但没有必要声称它们确实是临时的。

Any insight would help.任何见解都会有所帮助。

I can tell you from vast experience with Mongo and Docker (or any database for that matter);我可以通过使用 Mongo 和 Docker(或任何与此相关的任何数据库)的丰富经验告诉您; that is is better not to make an image with a database embedded.最好不要制作嵌入数据库的图像。

It can be done but one some platforms you can lose a lot of time getting it up to speed.它可以完成,但在某些平台上,您可能会花费大量时间来加快速度。

Recommendation: Keep you code and database on separate servers and bake in the DB credentials in your Docker image.建议:将代码和数据库保存在不同的服务器上,并在 Docker 映像中放入数据库凭据。

Host DB for free here https://mlab.com/在此处免费托管 DB https://mlab.com/

This is just my opinion please take many opinions and formulate your own.这只是我的意见,请采纳许多意见并制定自己的意见。 More reading here: https://vsupalov.com/database-in-docker/更多阅读: https : //vsupalov.com/database-in-docker/

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

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