下载
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.4.4.tgz
本地dockerfile
[root@yzb-centos72-3 software]# more dockerfile/mongodb
FROM centos
MAINTAINER jiangleid@163.com
RUN mkdir -p /home/software
WORKDIR /home/software
RUN yum install -y unzip zip;
RUN yum install -y net-tools
# '***** mongodb ******'
ADD mongodb-linux-x86_64-rhel70-3.4.4.tgz /usr/local/
RUN mv /usr/local/mongodb-linux-x86_64-rhel70-3.4.4 /usr/local/mongodb-3.4.4
ADD mongodb/ /usr/local/mongodb-3.4.4/conf/
RUN chmod -R 755 /usr/local/mongodb-3.4.4
本地mongodb 目录结构
[root@yzb-centos72-3 mongodb]# tree
.
├── config
│ ├── config_21000.conf
│ ├── db
│ └── log
├── mongos
│ ├── log
│ └── mongos_20000.conf
└── shard
├── shard1
│ ├── db
│ ├── log
│ └── shard1_22001.conf
├── shard2
│ ├── db
│ ├── log
│ └── shard2_22002.conf
└── shard3
├── db
├── log
└── shard3_22003.conf
15 directories, 5 files
基于dockerfile 构建影像
[root@yzb-centos72-3 software]# docker build -t mongodb:v1.0 -f dockerfile/mongodb .
Sending build context to Docker daemon 300.8 MB
Step 1 : FROM centos
---> a8493f5f50ff
Step 2 : MAINTAINER jiangleid@yonyou.com
---> Using cache
---> 44af6950f23e
Step 3 : RUN mkdir -p /home/software
---> Using cache
---> 5778393e7b40
Step 4 : WORKDIR /home/software
---> Using cache
---> ebdc5e58fd29
、、、、、、、、、
、、、、、、、、、
Step 10 : RUN chmod -R 755 /usr/local/mongodb-3.4.4
---> Running in 412af413e692
---> ede0c75edfac
Removing intermediate container 412af413e692
Successfully built ede0c75edfac
查看新建立的影像, 可以看到 iamge id: ede0c75edfac
[root@yzb-centos72-3 software]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mongodb v1.0 ede0c75edfac 2 minutes ago 1.183 GB
mariadb v1.0 5f1a79c3025b 19 hours ago 431.3 MB
nginx v1.0 896a46fdd902 22 hours ago 1.07 GB
docker.io/centos latest a8493f5f50ff 5 weeks ago 192.5 MB
docker.io/centos 7.3.1611 67591570dd29 5 months ago 191.8 MB
启动镜像
[root@yzb-centos72-3 software]# docker run -it -p 20000:20000 -p 21000:21000 -p 22001:22001 -p 22002:22002 -p 22003:22003 ede0c75edfac
[root@db5e67a0513a software]#
容器内的mongodb
[root@a24970088f14 mongodb-3.4.4]# ll
total 120
-rwxr-xr-x 1 root root 34520 Apr 20 22:20 GNU-AGPL-3.0
-rwxr-xr-x 1 root root 16726 Apr 20 22:20 MPL-2
-rwxr-xr-x 1 root root 1359 Apr 20 22:20 README
-rwxr-xr-x 1 root root 55625 Apr 20 22:20 THIRD-PARTY-NOTICES
drwxr-xr-x 2 root root 4096 May 18 00:52 bin
drwxr-xr-x 5 root root 44 May 18 00:52 conf
启动mongodb的 config shard mongos
进入bin目录
启动config
[root@a24970088f14 bin]# ./mongod -f ../conf/config/config_21000.conf
about to fork child process, waiting until server is ready for connections.
forked process: 35
child process started successfully, parent exiting
config_21000.conf 文件内容
[root@a24970088f14 bin]# more ../conf/config/config_21000.conf
replSet=cfgReplSet
configsvr=true
port=21000
dbpath=/usr/local/mongodb-3.4.4/conf/config/db
logpath=/usr/local/mongodb-3.4.4/conf/config/log/config.log
fork=true
登入config,配置 config副本集
[root@db5e67a0513a bin]# ./mongo --port 21000
MongoDB shell version v3.4.4
connecting to: mongodb://127.0.0.1:21000/
MongoDB server version: 3.4.4
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings:
2017-05-18T01:23:15.669+0000 I CONTROL [initandlisten]
2017-05-18T01:23:15.669+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-05-18T01:23:15.669+0000 I CONTROL [initand