1、创建项目目录mongo,在目录下上传下载的Mongodb安装文件及mongo.conf配置文件,创建Dockerfile文件,项目结构如下:
mongo
- Dockerfile
- mongo.conf
- mongodb-linux-x86_64-3.4.9.tgz
- data
- logs
Dockerfile内容如下:
# mongo# SOURCE_IMAGEFROM centos# MAINTAINER_INFOMAINTAINER bluemooder 897221533@qq.com# ENVENV MONGO_VERSION 3.4.9ENV PATH /usr/local/mongodb/bin:$PATH# BUILDADD mongodb-linux-x86_64-$MONGO_VERSION.tgz /usr/local/RUN mv /usr/local/mongodb-linux-x86_64-$MONGO_VERSION /usr/local/mongodb \ && cd /usr/local/mongodb \ && mkdir data logsCOPY mongo.conf /usr/local/mongodb/mongo.conf WORKDIR /usr/local/mongodb/# PORTEXPOSE 27017# RUNNIGCMD mongod --config mongo.conf
mongo.conf内容如下:
dbpath = /usr/local/mongodb/data/logpath = /usr/local/mongodb/logs/mongodb.logport = 27017logappend=truequiet=trueauth=true
2、根据Dockerfile创建自定义镜像
docker build -t mongo:3.4.9 .
3、运行Mongo容器
docker run -d --name zx-mongo -p 27017:27017 -v `pwd`/data:/usr/local/mongodb/data -v `pwd`/logs:/usr/local/mongodb/logs mongo:3.4.9
4、查看容器运行状态
docker ps -a | grep mongo7a1b42369830 mongo:3.4.9 "/bin/sh -c 'mongo..." 5 minutes ago Up 5 minutes 0.0.0.0:27017->27017/tcp zx-mongo
知行办公,专业移动办公平台
【总监】十二春秋之,;
【Master】zelo,;
【运营】运维艄公,;
【产品设计】流浪猫,;
【体验设计】兜兜,;
【iOS】淘码小工,;iMcG33K,;
【Android】人猿居士,;思路的顿悟,;
【java】首席工程师MR_W,;
【测试】土镜问道,;
【数据】喜乐多,;
【安全】保密,你懂的。