Here’s what the description of the mongo image spells out:
Initializing a fresh instance
When a container is started for the first time it will execute files with extensions
.shand.jsthat are found in/docker-entrypoint-initdb.d. Files will be executed in alphabetical order..jsfiles will be executed bymongousing the database specified by theMONGO_INITDB_DATABASEvariable, if it is present, ortestotherwise. You may also switch databases within the.jsscript.
You may want to try setting MONGO_INITDB_DATABASE.