I'm running MongoDB inside a larger server, controlled by docker-compose.
I'd like to reduce the verbosity of the Mongo logs (and probably eventually control other Mongo settings too). Not sure where to fit this into my minimal config; I currently just have:
mongo:
image: mongo:3.2
volumes:
- ${MONGO_DATA_DB}:/data/db
ports:
- ${EXPOSED_MONGO_PORT}:27017
Reading the description of the official image of MongoDB at DockerHub (same image you are using) I deduced that you can pass commands to mongod using command section of the docker-compose. Then you could use the --quiet
option to limit the amount of output.
In this way you docker-compose would be as follows:
mongo:
image: mongo:3.2
volumes:
- ${MONGO_DATA_DB}:/data/db
ports:
- ${EXPOSED_MONGO_PORT}:27017
command: --quiet
You can find the entire list of options that mongod accepts here or also check the --help
output of mongod
in your bash.
Sometimes docker images, accepts configuration params as an environment variables, so you could change the configuration of the service at runtime. Sadly I couldn't find any official information about available environment variables in this docker image, but I encourage you to continue investigating about this alternative path.
I hope it helps!
EDIT
Another approach from the image documentation:
For a more complicated configuration setup, you can still use the MongoDB configuration file. mongod does not read a configuration file by default, so the --config option with the path to the configuration file needs to be specified. Create a custom configuration file and put it in the container by either creating a custom Dockerfile FROM mongo or mounting it from the host machine to the container. See the MongoDB manual for a full list of configuration file options.
For example, /my/custom/mongod.conf is the path to the custom configuration file. Then start the MongoDB container like the following:
$ docker run --name some-mongo -v /my/custom:/etc/mongo -d mongo --config /etc/mongo/mongod.conf
In this way, your docker-compose would be as follows:
mongo:
image: mongo:3.2
volumes:
- ${MONGO_DATA_DB}:/data/db
- ${MONGO_DATA_CONFIG}:/etc/mongo/
ports:
- ${EXPOSED_MONGO_PORT}:27017
command: --config /etc/mongo/mongod.conf