1、创建项目目录并上传包
mkdir centos_mongodb cd centos_mongodb tar -zxvf mongodb-linux-x86_64-4.0.11.tgz
2、编辑配置文件
vi mongodb.conf
dbpath = /data/usr/mongodb/data logpath = /data/usr/mongodb/logs/mongodb.log port = 27017 fork = false bind_ip=0.0.0.0 auth = true
3、编辑Dockerfile
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
FROM centos:latest MAINTAINER xiaozhou (xiaozhou@docker.com) LABEL Discription="基于centos的mongodb镜像" version="1.0" RUN mkdir -p /data/usr ADD mongodb-linux-x86_64-4.0.11 /data/usr/mongodb RUN mkdir /data/usr/mongodb/{data,logs} ENV PATH /data/usr/mongodb/bin:$PATH EXPOSE 27017 WORKDIR /data/usr/mongodb/bin/ COPY mongodb.conf . CMD ["mongod","-f", "mongodb.conf"]
4、创建镜像容器
docker build -t centos:mongodb . mkdir -p /data/mongodb/{data,logs} docker run --name mongodb -d -p 27017:27017 -v /data/mongodb/data/:/data/usr/mongodb/data/ -v /data/mongodb/logs/:/data/usr/mongodb/logs/ -it centos:mongodb