我在网上找到相关资料然后按照下面的步骤搭建mongoDB 8.0 群集
下面是一个修改后的完整示例:
修改后的 docker-compose.yml
version: '3.8'services:mongodb-primary:image: mongo:latestcontainer_name: mongodb-primaryrestart: alwaysenvironment:MONGO_INITDB_ROOT_USERNAME: adminMONGO_INITDB_ROOT_PASSWORD: adminports:- "27017:27017"volumes:- mongo_data:/data/dbnetworks:- my-networkmongodb-secondary1:image: mongo:latestcontainer_name: mongodb-secondary1restart: alwaysenvironment:MONGO_INITDB_ROOT_USERNAME: adminMONGO_INITDB_ROOT_PASSWORD: adminvolumes:- mongo_data_secondary1:/data/dbnetworks:- my-networkmongodb-secondary2:image: mongo:latestcontainer_name: mongodb-secondary2restart: