"Docker" builds monogdb service image based on Dockerfile

Source: Internet
Author: User
Tags auth mongodb mongodb server git clone

① view content, including written dockerfile and a number of scripts.

Download the MongoDB mirroring project from the GitHub Dockerpool community account:

git clone https://github.com/DockerPool/Mongodb.git and modify the file

[[email protected] mongodb]# ls

Dockerfile Mongodb-3.2.repo mongodb-linux-x86_64-rhel70-3.6.0.tgz run.sh set_mongodb_password.sh


The contents of Dockerfile include:

[Email protected] mongodb]# VI Dockerfile

#设置从我们之前创建的sshd镜像继承

From Sshd:centos


Maintainer Waitfish from dockerpool.com


ADD mongodb-3.2.repo/etc/yum.repos.d/


RUN \

Yum update-y && \

yum install-y mongodb-org && \ #这里不推荐使用yum安装monodb, download speed is too slow

Yum Clean All


# Create a folder where MongoDB holds data files

RUN mkdir-p/data/db

volume/data/db


ENV AUTH Yes


# Add Run scripts adding script

ADD run.sh/run.sh

ADD set_mongodb_password.sh/set_mongodb_password.sh

RUN chmod 755./*.sh


EXPOSE 27017

EXPOSE 28017


CMD ["/run.sh"]

————————————————————————————————————————————————

[email protected] mongodb]# cat run.sh

#!/bin/bash

if [!-f/.mongodb_password_set]; Then

/set_mongodb_password.sh

Fi


If ["$AUTH" = = "yes"]; Then

Export mongodb= '/usr/bin/mongod--nojournal--auth--httpinterface--rest '

Else

Export mongodb= '/usr/bin/mongod--nojournal--httpinterface--rest '

Fi


if [!-f/data/db/mongod.lock]; Then

Eval $mongodb

Else

Export mongodb= $mongodb '--dbpath/data/db '

Rm/data/db/mongod.lock

Mongod--dbpath/data/db--repair && eval $mongodb

Fi

——————————————————————————————————————————————————

[email protected] mongodb]# cat set_mongodb_password.sh

#!/bin/bash


If [-f/.mongodb_password_set]; Then

echo "MongoDB Password already set!"

Exit 0

Fi


/usr/bin/mongod--smallfiles--nojournal &


pass=${mongodb_pass:-$ (pwgen-s 12 1)}

_word=$ ([${mongodb_pass}] && echo "Preset" | | echo "random")


Ret=1

while [[Ret-ne 0]]; Do

echo "= Waiting for confirmation of MongoDB service startup"

Sleep 5

MONGO admin--eval "Help" >/dev/null 2>&1

Ret=$?

Done


echo "= Creating an Admin user with a ${_word} password in MongoDB"

MONGO admin--eval "Db.adduser ({User: ' admin ', pwd: ' $PASS ', roles: [' useradminanydatabase ', ' Dbadminanydatabase ']});"

MONGO admin--eval "Db.shutdownserver ();"


echo "= done!"

Touch/.mongodb_password_set


echo "========================================================================"

echo "Can now connect to this MongoDB server using:"

echo ""

echo "MONGO admin-u admin-p $PASS--host

echo ""

echo "Remember to change the above password as soon as possible!"

echo "========================================================================"
















①②③④⑤⑥⑦⑧⑨⑩








"Docker" builds monogdb service image based on Dockerfile

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.