用户名:root
密码:123456
version: '3.1'
services:mongo:image: mongo:7container_name: mongorestart: alwaysports:- 27017:27017volumes:- /opt/data/mongo:/data/dbenvironment:TZ: Asia/ShanghaiMONGO_INITDB_ROOT_USERNAME: rootMONGO_INITDB_ROOT_PASSWORD: 123456mongo-express:image: mongo-expresscontainer_name: mongo-expressrestart: alwaysports:- 8081:8081environment:TZ: Asia/ShanghaiME_CONFIG_MONGODB_ADMINUSERNAME: rootME_CONFIG_MONGODB_ADMINPASSWORD: 123456ME_CONFIG_MONGODB_URL: mongodb://root:123456@mongo:27017/
web管理界面:
http://127.0.0.1:8081/
创建库和普通用户,demo库不存在会自动创建
use demo
db.createUser({user: "demo",pwd: "tangwan",roles: ["readWrite"]
})