Replies: 2 comments 2 replies
-
If you're using swarm, I'd suggest https://docs.docker.com/engine/swarm/secrets/ -- if you're not, I'd suggest considering it. 😄 I don't know if a |
Beta Was this translation helpful? Give feedback.
0 replies
-
If you are running Using |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to setup the
mongo
docker image in Docker Compose in such a way that:root
role is created on theadmin
database.readWrite
role on another database is created.I want username, password and database to come from environment variables. This is proving to be impossible with the current
mongo:5.0.8
image.This is the relevant part of my
docker-compose.yaml
:The
MONGO_USER
,MONGO_PASS
andREAD_STORE_DB
values are fetched from a.env
file.The
root
user is successfully created by the docker-entrypoint.sh script, so this part of the setup works just fine.The problem comes when I try to setup my database user on
docker-entrypoint-initdb.d
. I have the choice of using either a.js
or a.sh
file in there to achieve this, as described in the Initializing a fresh instance section of the documentation.Problem is that neither work for my intent and purposes, here is why:
.js
file - can not pass environment variables here, so I end up exposing the auth credentials on this file, which I want under revision control.sh
file - file is executed by usermongodb
, which causes 2 different problems:/home/mongodb
home directory does not exist, which causesmongosh
to fail. It runs fine as userroot
, or if I simply create the missing home directory.root
user, but not themongodb
user.So basically I have my hands tied. If I run my script manually as
root
after the container is up, everything works, but no way to get it to run properly by thedocker-entrypoint.sh
script.Maybe I am missing something here, if that is the case, lets properly document how to achieve this. I have seen countless threads regarding this issue and people struggling with this simple user creation, which could be solved with a simple example on the documentation page.
Beta Was this translation helpful? Give feedback.
All reactions