Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

411
Views
Docker MongoDB : UserNotFound

I am building a non-interactively configurable MongoDB image for Docker, with the current goal to be able to load auth users from a config file programmatically. My current problem is that albeit I can successfully add users to the database, they seem not to persist through the build process and as such my node container cannot successfully authenticate against the database.

Here's the main dockerfile for my mongodb instance:

FROM mongo:latest

#Installing Node
RUN apt-get update && \
    apt-get install -y curl && \
    curl -sL https://deb.nodesource.com/setup_6.x | bash - && \
    apt-get install -y nodejs

#Setting Up Mongo
WORKDIR /var/www/smq
COPY ./docker/mongo-setup.js mongo-setup.js
COPY ./.config/mongo /var/www/.config/mongo
RUN if [ -e /var/www/.config/mongo/mongod.conf ] ; then cp /var/www/.config/mongo/mongod.conf /etc/mongod.conf ; fi
RUN mongod --port 27017 & node mongo-setup.js && mongod --shutdown

CMD ["mongod", "--auth", "--port", "27017"]

My setup also relies on docker-compose:

  mongodb:
    build:
      context: ../
      dockerfile: ./docker/mongodb-dockerfile
    container_name: mongo_container
    volumes:
     - /data/db

At step RUN mongod --port 27017 & node mongo-setup.js && mongod --shutdown, I get the print showing successful creation of users via the mongo shell. However when the two docker containers (mongo & node) are connected, I get the following error from the mongod :

2017-01-02T20:43:14.895+0000 I ACCESS [conn1] SCRAM-SHA-1 authentication failed for mydbuser on mydb from client 172.20.0.3:49762 ; UserNotFound: Could not find user mydbuser@mydb

How can I resolve this issue?

Ultimately, this is an effort to open-source my setup, hence you can reproduce the step by pulling this repository from github (currently the said setup is under /node-mongo on the branch node-mongo). Cheers!

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!