一、宿主机创建目录,存放mongodb配置信息、数据信息
mkdir -p /usr/local/mymongo/conf
二、参考官方配置文档,配置mongod.conf
#在上面的conf目录下,创建mongod.conf
systemLog:
destination: file
path: /var/log/mongodb/mongod.log
logAppend: true
storage:
dbPath: /data/db
net:
bindIp: 0.0.0.0
port: 27017
setParameter:
enableLocalhostAuthBypass: false
security:
authorization: disabled
# 挂载配置文件 -v /usr/local/mymongo/conf:/etc/mongo
# 挂载数据 -v /usr/local/mymongo/data/db:/data/db
docker run -d --name my_mongo -v /usr/local/mymongo/conf:/etc/mongo -v /usr/local/mymongo/data/db:/data/db --restart=always mongo --config /etc/mongo/mongod.conf