mysql
值得注意的是,外部主机的IP地址是172.17.0.1, 限定IP地址登陆的时候要放行这个IP
1
| docker run -d --restart=always --name mariadb -e MYSQL_ROOT_PASSWORD=123456 -v ~/xxx/mariadb:/var/lib/mysql -p 127.0.0.1:3306:3306 mariadb
|
mongo
首先,配置好文件 Yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
storage: dbPath: /data/db journal: enabled: true
systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log
net: port: 27017 bindIp: 127.0.0.1
processManagement: timeZoneInfo: /usr/share/zoneinfo
security: authorization: enabled
|
1 2 3
| docker run --restart=always --name mongo -v ~/xxx/mongodb/config:/etc/mongo -v ~/xxx/mongodb/db:/data/db -p 27017:27017 -d mongo -f /etc/mongo/mongod.conf
docker exec -it mongo mongo
|
设置admin 权限
1 2 3 4 5 6
| use admin db.createUser({ user: 'admin', pwd: 'admin', roles: [{role: 'userAdminAnyDatabase', db: 'admin'}] });
|
新建数据库和用户
1 2 3 4 5 6
| use newDb db.createUser({ user: 'user', pwd: '123456', roles: [{role: 'dbOwner', db: 'userDb'}] });
|