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!