19

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
David Goldfarb
  • 1,796
  • 3
  • 18
  • 32

4 Answers4

27

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 
Carlos Bazilio
  • 830
  • 9
  • 20
20

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
Community
  • 1
  • 1
Emiliano Viotti
  • 1,619
  • 2
  • 16
  • 30
5

Setting logpath worked for me. It's not showing the logs output instead it's saving to the file.

    mongo:
        container_name: mongo
        image: mongo
        restart: unless-stopped
        command: 
            - '--logpath'
            - '/var/log/mongodb/mongod.log'
        ports:
            - '27017:27017'
Hasip Timurtas
  • 983
  • 2
  • 11
  • 20
0

An alternative MongoDB image by Bitnami offers this functionality via environment variables in compose file.

https://hub.docker.com/r/bitnami/mongodb. Explained in the section Configuring system log verbosity level

Emre
  • 933
  • 15
  • 27