Problem trying to connect Mongodb via Docker-Compose with Robo3t. How to complete the connection?

Asked

Viewed 129 times

1

I want to make a connection through Robo3t of a Mongodb database that is running via Docker-Compose.

version: '3'

services:
  mongo-express:
    image: mongo-express
    container_name: mongo-express
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_BASICAUTH_USERNAME: <usuario>
      ME_CONFIG_BASICAUTH_PASSWORD: <senha>
      ME_CONFIG_MONGODB_PORT: 27017
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: <senha>
    links:
      - mongo
    networks:
      - mongo-network

  mongo:
    image: mongo
    container_name: mongo
    environment:
      MONGO_INITDB_ROOT_USERNAME: <usuario>
      MONGO_INITDB_ROOT_PASSWORD: <senha>
    ports:
      - 27017:27017
    volumes:
      - ./datadir:/data/db
    networks:
      - mongo-network

networks: 
    mongo-network:
      driver: bridge

img-connection

img-connection

I’ve tried to change the authentication mechanisms and ports but gives the same message:

Cannot connect to the MongoDB at localhost:27017.

Error:
Authentication failed.

1 answer

1


Your Docker-Compose is correct. The problem is in connecting to the database.

As specified in Docker Hub:

These variables, used in Conjunction, create a new user and set that user’s password. This user is created in the admin Authentication database and Given the role of root, which is a "superuser" role.

That is, when using the environment variables MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD, the user is created as root in the database admin.

Therefore, it is necessary to specify admin in the field Database flap Authentication.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.