1.拉取镜像
代码语言:text复制docker pull mongo:latest
2.docker
部署
docker run -itd
--privileged=true
--name mongodb
-m "512M"
--restart always
-p "27017:27017"
mongo:latest
mongod --auth
3.docker-compose
部署
version: '3'
services:
mongo:
image: mongo:latest
container_name: mongodb
restart: always
ports:
- 27017:27017
command: mongod --auth
deploy:
resources:
limits:
cpus: '0.2'
memory: 512M
reservations:
cpus: '0.2'
memory: 512M
代码语言:text复制docker-compose -f mongo.yaml up [-d]
4.配置
代码语言:text复制docker exec -it mongodb mongo admin
代码语言:text复制db.createUser({ user:'scott',pwd:'scott',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]});
代码语言:text复制db.auth('scott', 'scott')