Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce mongo log verbosity in a docker-compose image?

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
like image 676
David Goldfarb Avatar asked Feb 14 '19 17:02

David Goldfarb


People also ask

How do I change the log level in a docker container?

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.

Which command is used to start the docker daemon process but also specifies the option for logging?

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.

Where can I find MongoDB logs on Mac?

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.

What is the command you will use to find the default logging driver used in docker?

So it is json-file with the actual log file path /var/lib/docker/containers/a48314f1c16356f3cf534b273ea3871a26882d1466979c48e38611d8106594df/a48314f1c16356f3cf534b273ea3871a26882d1466979c48e38611d8106594df-json.


2 Answers

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 
like image 94
Carlos Bazilio Avatar answered Sep 28 '22 02:09

Carlos Bazilio


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
like image 38
Emiliano Viotti Avatar answered Sep 28 '22 01:09

Emiliano Viotti