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
You can run the command kubectl exec -it <container_name> bash and use the command line inside the container to change the environment variable . You can do it by running the command export LOG_LEVEL=debug or export LOG_LEVEL=error inside the container.
Step 2 − Now we need to start the docker daemon process. But this time, we need to append the –l parameter to specify the logging option.
MongoDB logs can be found in the MongoDB log files at /var/log/mongodb/mongodb. log. If you can't find the log files from this location, you can check the mongodb. conf.
So it is json-file with the actual log file path /var/lib/docker/containers/a48314f1c16356f3cf534b273ea3871a26882d1466979c48e38611d8106594df/a48314f1c16356f3cf534b273ea3871a26882d1466979c48e38611d8106594df-json.
I've tried the accepted answer but mongo log was still quite verbose. Then, following this thread, I've omitted the whole log and it's much better in my case:
mongo:
command: mongod --quiet --logpath /dev/null
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With