Qual é a sua dúvida?
MongoDB e Docker via docker-compose.yml
Criando a rede
$ docker network create --subnet=172.50.50.0/16 devnetwork
docker-compose.yml
version: '3' services: mongo-express: container_name: mongo-express image: mongo-express:VERSION_HERE ports: - 7018:8081 environment: ME_CONFIG_BASICAUTH_USERNAME: admin ME_CONFIG_BASICAUTH_PASSWORD: docker ME_CONFIG_MONGODB_PORT: 27017 ME_CONFIG_MONGODB_ADMINUSERNAME: root ME_CONFIG_MONGODB_ADMINPASSWORD: docker links: - mongo networks: mongo-network: ipv4_address: 172.50.50.135 mongo: container_name: mongo image: mongo:VERSION_HERE environment: MONGO_INITDB_DATABASE: mydatabase ports: - 7017:27017 volumes: - mongo-data:/data/db networks: mongo-network: ipv4_address: 172.50.50.137 networks: mongo-network: external: name: devnetwork volumes: mongo-data:
Customizando configurações
mongo: container_name: mongo image: mongo:4.0 environment: MONGO_INITDB_DATABASE: mydatabase MONGO_INITDB_ROOT_USERNAME: root MONGO_INITDB_ROOT_PASSWORD: docker ports: - 7017:27017 volumes: - ./config/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro <==== AQUI ENTRA O ARQUIVO DE CUSTOMIZAÇÃO - mongo-data:/data/db
Arquivo init-mongo.js
db.createUser( { user: "root", pwd: "docker", roles: [ { role: "readWrite", db: "mydatabase" } ] } )
Clusters MongoDB no Docker
- https://github.com/minhhungit/mongodb-cluster-docker-compose
- https://github.com/minhhungit/mongodb-cluster-docker-compose/blob/master/docker-compose.yml
Exemplo de docker-compose.yml
version: '2' services: ## Router router01: image: mongo:4.0 container_name: rydell-router-01 command: mongos --port 27017 --configdb rs-config-server/configsvr01:27017,configsvr02:27017,configsvr03:27017 --bind_ip_all ports: - 27117:27017 volumes: - ./scripts:/scripts router02: image: mongo:4.0 container_name: rydell-router-02 command: mongos --port 27017 --configdb rs-config-server/configsvr01:27017,configsvr02:27017,configsvr03:27017 --bind_ip_all volumes: - ./scripts:/scripts ports: - 27118:27017 links: - router01 ## Config Servers configsvr01: image: mongo:4.0 container_name: rydell-mongo-config-01 command: mongod --port 27017 --configsvr --replSet rs-config-server volumes: - ./scripts:/scripts ports: - 27119:27017 links: - shard01-a - shard02-a - shard03-a configsvr02: image: mongo:4.0 container_name: rydell-mongo-config-02 command: mongod --port 27017 --configsvr --replSet rs-config-server volumes: - ./scripts:/scripts ports: - 27120:27017 links: - configsvr01 configsvr03: image: mongo:4.0 container_name: rydell-mongo-config-03 command: mongod --port 27017 --configsvr --replSet rs-config-server volumes: - ./scripts:/scripts ports: - 27121:27017 links: - configsvr02 ## Shards ## Shards 01 shard01-a: image: mongo:4.0 container_name: rydell-shard-01-node-a command: mongod --port 27017 --shardsvr --replSet rs-shard-01 volumes: - ./scripts:/scripts ports: - 27122:27017 links: - shard01-b - shard01-c shard01-b: image: mongo:4.0 container_name: rydell-shard-01-node-b command: mongod --port 27017 --shardsvr --replSet rs-shard-01 volumes: - ./scripts:/scripts ports: - 27123:27017 shard01-c: image: mongo:4.0 container_name: rydell-shard-01-node-c command: mongod --port 27017 --shardsvr --replSet rs-shard-01 volumes: - ./scripts:/scripts ports: - 27124:27017 ## Shards 02 shard02-a: image: mongo:4.0 container_name: rydell-shard-02-node-a command: mongod --port 27017 --shardsvr --replSet rs-shard-02 volumes: - ./scripts:/scripts ports: - 27125:27017 links: - shard02-b - shard02-c shard02-b: image: mongo:4.0 container_name: rydell-shard-02-node-b command: mongod --port 27017 --shardsvr --replSet rs-shard-02 volumes: - ./scripts:/scripts ports: - 27126:27017 shard02-c: image: mongo:4.0 container_name: rydell-shard-02-node-c command: mongod --port 27017 --shardsvr --replSet rs-shard-02 volumes: - ./scripts:/scripts ports: - 27127:27017 ## Shards 03 shard03-a: image: mongo:4.0 container_name: rydell-shard-03-node-a command: mongod --port 27017 --shardsvr --replSet rs-shard-03 volumes: - ./scripts:/scripts ports: - 27128:27017 links: - shard03-b - shard03-c shard03-b: image: mongo:4.0 container_name: rydell-shard-03-node-b command: mongod --port 27017 --shardsvr --replSet rs-shard-03 volumes: - ./scripts:/scripts ports: - 27129:27017 shard03-c: image: mongo:4.0 container_name: rydell-shard-03-node-c command: mongod --port 27017 --shardsvr --replSet rs-shard-03 volumes: - ./scripts:/scripts ports: - 27130:27017