Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to connect to concrete database in docker-compose

I have next setup of docker-compose.yaml

name: test-app-to-delete

services:
  mongo:
    image: mongo
    restart: always
    networks:
      - mongo
    volumes:
      - db:/data/db:rw
    environment:
      MONGO_INITDB_ROOT_USERNAME: 'user'
      MONGO_INITDB_ROOT_PASSWORD: 'password'
      MONGO_INITDB_DATABASE: 'db-name'

  mongo-express:
    image: mongo-express
    restart: always
    networks:
      - mongo
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: user
      ME_CONFIG_MONGODB_ADMINPASSWORD: password
      ME_CONFIG_MONGODB_URL: mongodb://user:password@mongo:27017/db-name

networks:
  mongo:

volumes:
  db:

So issue become a problem when I’m adding db-name to this configuration.

Errors:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Could not connect to database using connectionString: 
mongodb://user:password@mongo:27017/db-name

Just for note: I’m recreated database before run this configuration, so issue not in cached data.

>Solution :

You can try mongodb://user:password@localhost:27017/db-name?authSource=admin instead of your current connection string.
And make sure to use base64 converted values for username and password

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading