在Docker容器中保护Mongo

目前正在考虑在容器中部署mongo。 到目前为止我的文件看起来像,

############################################################ # Dockerfile to build Mongo Containers # Based on Ubuntu ############################################################ # Set the base image to Ubuntu FROM ubuntu:14.04 # File Author / Maintainer MAINTAINER Maintaner felix001 # Create repo file RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 RUN echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.0.list # Update the default application repository sources list RUN apt-get update && apt-get install -y \ mongodb-org \ vim # Create the MongoDB data directory RUN mkdir -p /data/db # Expose port 27017 from the container to the host EXPOSE 27017 # Set usr/bin/mongod as the dockerized entry-point application ENTRYPOINT ["/usr/bin/mongod"] 

不过,我需要lockingmongo,所以你需要一个密码来执行任何pipe理操作,并创build一个数据库/用户。 所以我的问题是2倍,

  1. 什么是保证最好的方法? 到目前为止,我有,

     vim /etc/mongod.conf + auth = true use admin db.createUser({ user:"admin", pwd:"secretpassword", roles: ["dbAdminAnyDatabase","clusterAdmin"]}) use example db.createUser({ user:"user1", pwd:"abc123", roles:["readWrite"] }) 
  2. 将此添加到Dockerfile的最佳方法是什么?

谢谢,

我不会推荐“烘焙”证书到您的图像。 您创build的每个数据库都将具有相同的密码。

举个例子,看一下tutum mongodb镜像,容器运行一个脚本,在启动时设置密码:

最后,我将有关环境variables用于密码的相关问题提交给您:

  • 指定Docker容器的超级用户PostgreSQL密码