mongo docker-compose

pull/241/head
wangchuxiao 2 years ago
parent 5b4f94832d
commit 834b88f68f

@ -28,8 +28,8 @@ mongo:
dbTimeout: 60 dbTimeout: 60
dbDatabase: openIM #mongo db 默认即可 dbDatabase: openIM #mongo db 默认即可
dbSource: admin dbSource: admin
dbUserName: #mongo用户名建议先不设置 dbUserName: openIM #mongo用户名建议先不设置
dbPassword: #mongo密码建议先不设置 dbPassword: openIM #mongo密码建议先不设置
dbMaxPoolSize: 100 dbMaxPoolSize: 100
dbRetainChatRecords: 3650 #mongo保存离线消息时间根据需求修改 dbRetainChatRecords: 3650 #mongo保存离线消息时间根据需求修改

@ -20,17 +20,21 @@ services:
ports: ports:
- 37017:27017 - 37017:27017
container_name: mongo container_name: mongo
command: --wiredTigerCacheSizeGB 1 command: --wiredTigerCacheSizeGB 1 --auth
volumes: volumes:
- ./components/mongodb/data/db:/data/db - ./components/mongodb/data/db:/data/db
- ./components/mongodb/data/logs:/data/logs - ./components/mongodb/data/logs:/data/logs
- ./components/mongodb/data/conf:/etc/mongo - ./components/mongodb/data/conf:/etc/mongo
- ./script/mongo-init.sh:/docker-entrypoint-initdb.d/mongo-init.sh
environment: environment:
- TZ=Asia/Shanghai - TZ=Asia/Shanghai
# cache # cache
- wiredTigerCacheSizeGB=1 - wiredTigerCacheSizeGB=1
#- MONGO_INITDB_ROOT_USERNAME=openIM MONGO_USERNAME: openIM
#- MONGO_INITDB_ROOT_PASSWORD=openIM MONGO_PASSWORD: openIM
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: root
MONGO_INITDB_DATABASE: openIM
#TZ: Asia/Shanghai #TZ: Asia/Shanghai
restart: always restart: always

@ -0,0 +1,12 @@
mongo -- "$MONGO_INITDB_DATABASE" <<EOF
db = db.getSiblingDB('admin')
db.auth('$MONGO_INITDB_ROOT_USERNAME', '$MONGO_INITDB_ROOT_PASSWORD')
db = db.getSiblingDB('$MONGO_INITDB_DATABASE')
db.createUser({
user: "$MONGO_USERNAME",
pwd: "$MONGO_PASSWORD",
roles: [
{ role: 'readWrite', db: '$MONGO_INITDB_DATABASE' }
]
})
EOF
Loading…
Cancel
Save