demshin
demshin

Reputation: 3

How to create few users for mongodb in docker-compose.yml?

I have a nodejs app with redis and mongodb and I need to create a few init user for mongodb. I know how to create the root user:

mongo:
image: mongo:latest
env_file: .env
environment:   
  MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
  MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
  MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE}

How to create one more user in docker-compose or in a different way?

Upvotes: 0

Views: 673

Answers (1)

Mike Doe
Mike Doe

Reputation: 17604

This can't be done this way. This is by design.

There's a walk around though, mount a shell script (file name ending with .sh) or a javascript script (file name ending with .js) inside the /docker-entrypoint-initdb.d and it will get executed on runtime. Using it create as many users as you want.

See how to initialize a fresh instance.

Upvotes: 1

Related Questions