When running the mongo
docker container, you can initialize your database by adding a script to the container's /docker-entrypoint-initdb.d
directory. The docs for this feature are under 'Initializing a fresh instance'.
If you do this, the mongo server mongod
runs two times. The init scripts are executed against a first, temporary mongod
instance. Once this instance shuts down, a second, real instance is started and runs forever.
The problem is that any config file applies only to the real instance and not the temporary one.
The docs specify only three env variables to configure the first instance:
MONGO_INITDB_ROOT_USERNAME
MONGO_INITDB_ROOT_PASSWORD
MONGO_INITDB_DATABASE
None of these has anything to do with logging. I checked the source code of the docker image and unfortunately, there don't seem to be any other undocumented env variables.
I was thinking about setting the log file at runtime using mongosh
, but this does not seem possible. The closest thing you can do is to set the verbosity.
CodePudding user response:
Create a config file with required logging settings https://www.mongodb.com/docs/manual/reference/configuration-options/#systemlog-options. e.g.
systemLog:
verbosity: 5
path: /tmp/mongodb_init.log
Map it as /tmp/docker-entrypoint-temp-config.json
, e.g.
docker run -d -v /path/to/the/file.conf:/tmp/docker-entrypoint-temp-config.json mongo