Docker/Mongo/Mongo-Express image not accepting YAML credentials

49 Views Asked by At

Hope you're all doing well. I'm encountering something I'm a little suprised by. I don't know if I'm not asking the question right, or what but I have not been able to find someone who is experiencing this circumstance (which seems strange to me).

I've configured a docker configuration (docker-compose.yml) that includes credentials for the user in the mongo-express environment. I am not encountering any error, but it won't let me use the credentials I've configured. Instead of getting rejection message or error, it's just clearing the credentials I've entered and it is not doing anything.

Below you will find the YML file I've used to configure the different images. You can find the complete body of code here

Please see the YML file below:

version: '3'
services:
  frontend:
    restart: always
    build: ./frontend
    ports:
      - '3000:3000'
    volumes:
      - /app/node_modules
      - ./frontend:/app
    environment: 
      - CHOKIDAR_USEPOLLING=true
  api:
    restart: always
    build: ./api
    ports:
      - '5050:5050'
    volumes:
      - ./api:/app
  mongo:
    image: mongo
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: very-strong-db-password
    volumes:
      - mongodb_data:/data/db
  mongo-express:
    image: mongo-express
    restart: always
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_SERVER: mongo
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: very-strong-db-password
    depends_on:
      - mongo

volumes:
  mongodb_data:
1

There are 1 best solutions below

0
datawookie On BEST ANSWER

You might have seen something like this in the logs:

Mongo Express server listening at http://0.0.0.0:8081
Server is open to allow connections from anyone (0.0.0.0)
basicAuth credentials are "admin:pass", it is recommended you change this in config.js!

That indicates that Mongo Express is still using the default credentials for HTTP authentication.

You can change these with the ME_CONFIG_BASICAUTH_USERNAME and ME_CONFIG_BASICAUTH_PASSWORD environment variables.

Revised docker-compose.yml:

version: '3'
services:
  frontend:
    restart: always
    build: ./frontend
    ports:
      - '3000:3000'
    volumes:
      - /app/node_modules
      - ./frontend:/app
    environment: 
      - CHOKIDAR_USEPOLLING=true
  api:
    restart: always
    build: ./api
    ports:
      - '5050:5050'
    volumes:
      - ./api:/app
  mongo:
    image: mongo
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: very-strong-db-password
    volumes:
      - mongodb_data:/data/db
  mongo-express:
    image: mongo-express
    restart: always
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_SERVER: mongo
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: very-strong-db-password
      #  This is where we specify the password for Mongo Express.
      ME_CONFIG_BASICAUTH_PASSWORD: RM4PB#*Fi6rvU@yqYtuocpjW
    depends_on:
      - mongo

volumes:
  mongodb_data:

I have not specified a new username for HTTP authentication (so just use the default admin) but have put in a cryptic one for the password. You can change the username too if you wish.

enter image description here