注意:以下文档只适用于TOP接口,请谨慎使用!

文档中心 > 容器服务

mongodb镜像示例

更新时间:2016/01/28 访问次数:28947
文件名称 说明
dockfile docker镜像构建描述文件
start ews镜像启动脚本
check ews镜像健康检查脚本

制作mongodb镜像镜像的dockfile如下:

from registry.acs.aliyun.com/open/centos:3.0.0
RUN cd /acs/user && wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.2.tgz && \
tar xzf mongodb-linux-x86_64-3.0.2.tgz && rm -fr mongodb-linux-x86_64-3.0.2.tgz && mv mongodb-linux-x86_64-3.0.2 mongodb && \
echo "export PATH=$PATH:/acs/user/mongodb/bin/" >> /root/.bash_profile && \
echo "export PATH=$PATH:/acs/user/mongodb/bin/" >> /acs/user/.bash_profile
COPY start /acs/bin/start
COPY check /acs/bin/check
ENV PATH $PATH:/acs/user/mongodb/bin

start脚本如下:

#!/bin/bash
env_file=/acs/conf/env.properties
config_file=/acs/user/mongodb/mongod.conf
if [ -f $env_file ];then
    mongodb_port=`cat $env_file|grep -w port.mainport|awk -F "=" '{print $2}'`
    mongodb_bind_ip=`cat $env_file|grep -w mongodb.bind_ip|awk -F "=" '{print $2}'`
    mongodb_maxConns=`cat $env_file|grep -w mongodb.maxConns|awk -F "=" '{print $2}'`
    mongodb_logappend=`cat $env_file|grep -w mongodb.logappend|awk -F "=" '{print $2}'`
    mongodb_master=`cat $env_file|grep -w mongodb.master|awk -F "=" '{print $2}'`
    mongodb_slave=`cat $env_file|grep -w mongodb.slave|awk -F "=" '{print $2}'`
    mongodb_source=`cat $env_file|grep -w mongodb.source|awk -F "=" '{print $2}'`
    mongodb_auth=`cat $env_file|grep -w mongodb.auth|awk -F "=" '{print $2}'`
    mongodb_conf_file=`cat $env_file|grep -w mongodb.conf.file|sed "s/^$mongodb.conf.file=//"`
    if [ "$mongodb_conf_file" != "" ];then
        wget -O $config_file $mongodb_conf_file
    else
        if [ -z "$mongodb_port" ];then
            mongodb_port=27017
        fi
        if [ -z "$mongodb_bind_ip" ];then
            mongodb_bind_ip=127.0.0.1
        fi
        if [ -z "$mongodb_maxConns" ];then
            mongodb_maxConns=1024
        fi
        if [ -z "$mongodb_logappend" ];then
            mongodb_logappend=false
        fi
        if [ -z "$mongodb_auth" ];then
            mongodb_auth=false
        fi
        echo "fork=true" > $config_file
        echo "port=$mongodb_port" >> $config_file
        echo "logpath=/acs/log/mongodb.log" >> $config_file
        echo "dbpath=/acs/data" >> $config_file
        echo "bind_ip=$mongodb_bind_ip" >> $config_file
        echo "maxConns=$mongodb_maxConns" >> $config_file
        echo "logappend=$mongodb_logappend" >> $config_file
        echo "pidfilepath=/acs/user/mongo.pid" >> $config_file
        if [ "$mongodb_master" != "" ];then
            echo "master=$mongodb_master" >> $config_file
        fi
        if [ "$mongodb_slave" != "" ];then
            echo "slave=$mongodb_slave" >> $config_file
        fi
        if [ "$mongodb_auth" != "" ];then
            echo "auth=$mongodb_auth" >> $config_file
        fi
        if [ "$mongodb_source" != "" ];then
            echo "source=$mongodb_source" >> $config_file
        fi
    fi
fi
echo "################################### Start MongoDB ###################################"
if [ ! -d "/acs/log" ];then
    mkdir -p /acs/log
fi
if [ ! -d "/acs/data" ];then
    mkdir -p /acs/data
fi
/acs/user/mongodb/bin/mongod -f $config_file
if [ $? != 0 ]; then
    echo "start mongodb failed"
exit 1
fi
echo "start mongodb success"
exit 0

check脚本如下

#!/bin/bash
if [ "`ps aux|grep mongo|grep -v grep|wc -l`" -eq 0 ];then
    echo "failed"
    exit 1
fi
echo "success"
exit 0

FAQ

关于此文档暂时还没有FAQ
返回
顶部