I am creating mongo:latest container on my machine using docker-compose.
This is my docker-compose.yaml:
version: '3.6'
services:
  backend:
    image: backend:1.0.0
    container_name: backend
    ports:
      - '5000:5000'
    links:
      - mongodb
    environment:
      NODE_ENV: PRODUCTION
      API_PORT: 5000
      MONGO_USERNAME: root
      MONGO_PASSWORD: rootPassXXX
      MONGO_HOST: mongodb
      MONGO_PORT: 27017
      MONGO_DATABASE: automatic
      JWT_TOKEN: Auto
  scheduler:
    image: scheduler:1.0.0
    container_name: scheduler
    links:
      - mongodb
    environment:
      NODE_ENV: PRODUCTION
      API_PORT: 5000
      MONGO_USERNAME: root
      MONGO_PASSWORD: rootPassXXX
      MONGO_HOST: mongodb
      MONGO_PORT: 27017
      MONGO_DATABASE: automatic
  mongodb:
    image: mongo
    container_name: mongodb
    expose:
      - 27017
    ports:
      - '27017:27017'
    environment:
      - MONGO_INITDB_ROOT_USERNAME=root
      - MONGO_INITDB_ROOT_PASSWORD=rootPassXXX
    volumes:
      - ./conf/mongodb:/data/db
volumes:
  autoc:
    external: true
    
networks: 
  default: 
    external: 
      name: automatic 
After creating those containers I am receiving from them an error: MongoServerError: Authentication failed.
This is the URI that the application is trying to connect: mongodb://root:rootPassXXX@mongodb:27017/matiautomai.
While trying to investigate what was happening, I was trying to log in to the same mongo container
that initializes with the user name and password variables without the credentials using that way: mongodb://mongodb:27017/automatic, And the application manages to connect to it.
I've reviewed the docs inside the Docker hub and it seems to be that I used the environment variables in the correct way.
What am I missing here?
 
    