生成密钥文件
openssl rand -base64 756 > mongodb.key
chmod 400 mongodb.key # 权限必须为400:ml-citation{ref="4" data="citationList"}
chown 999:999 mongodb.key # MongoDB容器用户ID为999:ml-citation{ref="4" data="citationList"}
docker-compose文件
version: '3.8'
services:
mongo1:
image: mongo:latest
container_name: mongo1
restart: always
ports:
- "27017:27017"
volumes:
- ./mongo1/data:/data/db
- ./mongodb.key:/etc/mongo/mongodb.key # 挂载密钥文件:ml-citation{ref="2,3" data="citationList"}
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: exam