Docker安装并配置Mongodb4.0
#初始化复制配置#创建数据目录
sudo mkdir -p /app/mongodb4-0/db
sudo mkdir -p /app/mongodb4-0/configdb
sudo chmod -R 777 /app/mongodb4-0/db
sudo chmod -R 777 /app/mongodb4-0/configdb
#初始化配置文件
sudo cat > /app/mongodb4-0/configdb/mongod.conf <<EOF
net:
port: 27017
bindIpAll: true
security:
authorization: enabled
storage:
wiredTiger:
engineConfig:
cacheSizeGB: 2
EOF
#安装mongodb-3.0
sudo docker run -d \
--network host \
--restart=always \
-v /app/mongodb4-0/db:/data/db \
-v /app/mongodb4-0/configdb:/data/configdb \
-v /etc/localtime:/etc/localtime:ro \
--name mongodb4-0 mongo:4 mongod \
-f /data/configdb/mongod.conf
#进入容器
docker exec -it mongodb4-0 /bin/bash
#登录数据库
mongo --port=27017
#切换到admin数据库
use admin
#创建管理员账号
db.createUser(
{
user: "admin",
pwd: "123456",
roles: [ { role: "root", db: "admin" } ]
}
);
#登录
db.auth('admin', '123456')