0

I use this docker-compose which runs MongoDB+ mongo-express Web interface: https://gist.github.com/adamelliotfields/cd49f056deab05250876286d7657dc4b

How can I run docker(s) with mongodb cluster and mongo-express as web interface?

A have attached my docker-compose file: I have got it from bitnami and added mongo-express. But web interface does not work.

That is:

version: '3.1'

services:   mongodb-sharded:
    image: docker.io/bitnami/mongodb-sharded:4.4
    environment:
      - MONGODB_ADVERTISED_HOSTNAME=mongodb-sharded
      - MONGODB_SHARDING_MODE=mongos
      - MONGODB_CFG_PRIMARY_HOST=mongodb-cfg
      - MONGODB_CFG_REPLICA_SET_NAME=cfgreplicaset
      - MONGODB_REPLICA_SET_KEY=replicasetkey123
      - MONGODB_ROOT_PASSWORD=example
    ports:
      - "27017:27017"

  mongodb-shard0:
    image: docker.io/bitnami/mongodb-sharded:4.4
    environment:
      - MONGODB_ADVERTISED_HOSTNAME=mongodb-shard0
      - MONGODB_SHARDING_MODE=shardsvr
      - MONGODB_MONGOS_HOST=mongodb-sharded
      - MONGODB_ROOT_PASSWORD=example
      - MONGODB_REPLICA_SET_MODE=primary
      - MONGODB_REPLICA_SET_KEY=replicasetkey123
      - MONGODB_REPLICA_SET_NAME=shard0
    volumes:
      - 'shard0_data:/bitnami'

  mongodb-cfg:
    image: docker.io/bitnami/mongodb-sharded:4.4
    environment:
      - MONGODB_ADVERTISED_HOSTNAME=mongodb-cfg
      - MONGODB_SHARDING_MODE=configsvr
      - MONGODB_ROOT_PASSWORD=example
      - MONGODB_REPLICA_SET_MODE=primary
      - MONGODB_REPLICA_SET_KEY=replicasetkey123
      - MONGODB_REPLICA_SET_NAME=cfgreplicaset
    volumes:
      - 'cfg_data:/bitnami'
         mongo-express:
    image: mongo-express
    restart: always
    ports:
     - 8081:8081
#        - 27017:27017      
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: example
      XX_CONFIG_MONGODB_URL: mongodb://root:example@mongodb-sharded:27017/
      ME_CONFIG_MONGODB_URL: mongodb://root:example@mongodb-cfg:27017/      
#      ongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]

       volumes:   shard0_data:
    driver: local   cfg_data:
    driver: local
ZedZip
  • 5,794
  • 15
  • 66
  • 119
  • https://stackoverflow.com/questions/42190267/replica-set-mongo-docker-compose for replica set, then update connection string on mongo-express container. – Alex Blex Jan 06 '22 at 10:20
  • I did not find there how can I add mongo-express and use it for the cluster – ZedZip Jan 06 '22 at 11:05
  • Don't you already have mongo-express in your docker-compose? you just need to change connection string to point to the replica set instead of a standalone mongo: https://docs.mongodb.com/manual/reference/connection-string/ – Alex Blex Jan 06 '22 at 11:18
  • I have added the link to my docker-compose file with mongo-express added but web interface does not work "we.tl/t-No0roxtRz8" – ZedZip Jan 06 '22 at 11:40
  • ok, so it's basically a copy paste of random strings from the internet. First of all it's not a valid format for docker-compose. Them, you are using bitnami image, not the official ones from the original gist. Nothing wrong with it but configuration will be completely different. Next, it says you are trying to set up sharded cluster, not just a replica set, is it the intention? Just to make it clear a minimal configuration of a cluster with 2 shards contains 10 mongodb containers: https://docs.mongodb.com/manual/core/sharded-cluster-components/ unless bitnami combined multiple nodes together. – Alex Blex Jan 06 '22 at 12:51
  • Ah, I see. Thank you. Will follow your recommendations and write again later. – ZedZip Jan 06 '22 at 13:06
  • @AlexBlex by the way: I do not use "copy-paste random strings" but I 've got github.com/bitnami/bitnami-docker-mongodb-sharded and tried to add mongo-express to it – ZedZip Jan 06 '22 at 16:56

0 Answers0