1、创建项目目录mongo,在目录下上传下载的Mongodb安装文件及mongo.conf配置文件,创建Dockerfile文件,项目结构如下:
mongo
- Dockerfile
- mongo.conf
- mongodb-linux-x86_64-3.4.9.tgz
- data
- logs
Dockerfile内容如下:
# mongo # SOURCE_IMAGE FROM centos # MAINTAINER_INFO MAINTAINER bluemooder [email protected] # ENV ENV MONGO_VERSION 3.4.9 ENV PATH /usr/local/mongodb/bin:$PATH # BUILD ADD 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 logs COPY mongo.conf /usr/local/mongodb/mongo.conf WORKDIR /usr/local/mongodb/ # PORT EXPOSE 27017 # RUNNIG CMD mongod --config mongo.conf && tail -f logs/mongodb.log
mongo.conf内容如下:
dbpath = /usr/local/mongodb/data/ logpath = /usr/local/mongodb/logs/mongodb.log port = 27017 fork = true logappend=true quiet=true journal=true auth=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 mongo 7a1b42369830 mongo:3.4.9 "/bin/sh -c ‘mongo..." 5 minutes ago Up 5 minutes 0.0.0.0:27017->27017/tcp zx-mongo
知行办公,专业移动办公平台
【总监】十二春秋之,[email protected];
【Master】zelo,[email protected];
【运营】运维艄公,[email protected];
【产品设计】流浪猫,[email protected];
【体验设计】兜兜,[email protected];
【iOS】淘码小工,[email protected];iMcG33K,[email protected];
【Android】人猿居士,[email protected];思路的顿悟,[email protected];
【java】首席工程师MR_W,[email protected];
【测试】土镜问道,[email protected];
【数据】喜乐多,[email protected];
【安全】保密,你懂的。
时间: 2024-10-24 22:42:44