It seems that MongoDB envs don’t create user and database. I was thinking to run a command in the container with setup.js to create user and database. Maybe you know a better solution?
When a container is started for the first time it will execute files with extensions .sh and .js that are found in /docker-entrypoint-initdb.d . Files will be executed in alphabetical order. .js files will be executed by mongo using the database specified by the MONGO_INITDB_DATABASE variable, if it is present, or test otherwise. You may also switch databases within the .js script.
You may want to try setting MONGO_INITDB_DATABASE.
Please note if you’re running services that depend on it, the first boot (because it runs the init script) may error. For example, my saas-api service fails on the first load 1/3 times