docker-library / docker-library/mongo

MongoDB container environment variables not applied for authentication

Open
#715 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Shell
Stars
1.1k
Forks
658
Avg merge
4h 40m
Merged PRs (30d)
1

Description

I'm running a MongoDB instance as a Windows container using Docker Compose, and I'm having trouble with MongoDB authentication. Although I’ve set the MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD environment variables, MongoDB Compass fails authentication when I attempt to connect using these credentials. If I remove the username and password from the connection string in MongoDB Compass, I can connect without issues, which suggests the environment variables might not be applied correctly.

Docker Compose Configuration:

services:
  mongo:
    image: mongo
    restart: always
    ports:
      - 27017:27017
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example

Steps to Reproduce:

  1. Start the MongoDB container using the above Docker Compose configuration.
  2. Try connecting with MongoDB Compass using the following credentials.
    • Username: root
    • Password: example

Expected Behavior:
The MongoDB container should start with the specified root username and password, allowing authentication via MongoDB Compass.

Actual Behavior:
MongoDB Compass fails to authenticate with the provided credentials. However, I can connect without authentication if I omit the username and password from the connection string.

Question:
Why are the environment variables not being applied to the MongoDB container for authentication?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Windows Docker Compose setup and inspecting the container's initialization behavior and connection details. No repository file or test is identified; the work is complete only once the authentication behavior and required configuration are established clearly enough to define a repository change.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, docker-compose, mongodb
Domain
databases, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.