From 834b88f68f60fc474196705c0af4458e3b4b51ca Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 1 Jul 2022 16:41:47 +0800 Subject: [PATCH] mongo docker-compose --- config/config.yaml | 4 ++-- docker-compose.yaml | 10 +++++++--- script/mongo-init.sh | 12 ++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 script/mongo-init.sh diff --git a/config/config.yaml b/config/config.yaml index bf9f3309c..10fa18cf5 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -28,8 +28,8 @@ mongo: dbTimeout: 60 dbDatabase: openIM #mongo db 默认即可 dbSource: admin - dbUserName: #mongo用户名,建议先不设置 - dbPassword: #mongo密码,建议先不设置 + dbUserName: openIM #mongo用户名,建议先不设置 + dbPassword: openIM #mongo密码,建议先不设置 dbMaxPoolSize: 100 dbRetainChatRecords: 3650 #mongo保存离线消息时间(天),根据需求修改 diff --git a/docker-compose.yaml b/docker-compose.yaml index 5f72bde6f..39b2888c8 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -20,17 +20,21 @@ services: ports: - 37017:27017 container_name: mongo - command: --wiredTigerCacheSizeGB 1 + command: --wiredTigerCacheSizeGB 1 --auth volumes: - ./components/mongodb/data/db:/data/db - ./components/mongodb/data/logs:/data/logs - ./components/mongodb/data/conf:/etc/mongo + - ./script/mongo-init.sh:/docker-entrypoint-initdb.d/mongo-init.sh environment: - TZ=Asia/Shanghai # cache - wiredTigerCacheSizeGB=1 - #- MONGO_INITDB_ROOT_USERNAME=openIM - #- MONGO_INITDB_ROOT_PASSWORD=openIM + MONGO_USERNAME: openIM + MONGO_PASSWORD: openIM + MONGO_INITDB_ROOT_USERNAME: root + MONGO_INITDB_ROOT_PASSWORD: root + MONGO_INITDB_DATABASE: openIM #TZ: Asia/Shanghai restart: always diff --git a/script/mongo-init.sh b/script/mongo-init.sh new file mode 100644 index 000000000..ad9c84428 --- /dev/null +++ b/script/mongo-init.sh @@ -0,0 +1,12 @@ +mongo -- "$MONGO_INITDB_DATABASE" <