How would one go about loading a custom configuration file using this docker image?
Using the data volume approach you can load your custom config file into your container, something like the following one:
$docker run --name mongo -d -v your/host/dir:/container/dir mongo:3.2 mongod -f /container/dir/mongod.conf
if this is what you need.
@ozlerhakan I use this command to run, container exit in second, and no log.
@jolestar Here is a working command that I use on windows 10 if your docker host resides in a virtualbox,
$ docker run --name mongo -d -v //c/Users/Hakan/config:/mongodb mongo:3.2 mongod -f //mongodb/mongod.conf
@ozlerhakan thanks reply.
I find the reason, my mongod.conf include systemLog config option, I try comment it, the command works. but I do not know why.
@jolestar I forgot to show you an example of a config file, see this for example:
storage:
dbPath: /data/db
directoryPerDB: true
journal:
enabled: true
engine: wiredTiger
net:
port: 27017
But if you have the systemLog section, you cannot see anything when doing docker logs :
storage:
dbPath: /data/db
directoryPerDB: true
journal:
enabled: true
engine: wiredTiger
net:
port: 27017
systemLog:
destination: file
logAppend: false
path: /data/mongod.log
@ozlerhakan but i need use --fork option.
when I run mongodb docker container i get this out put
about to fork child process, waiting until server is ready for connections.
forked process: 30
child process started successfully, parent exiting
and docker container Exited.
thx.
did you try -d out instead --fork @asdr14 ?
@ozlerhakan docker run with -d?
yes, what do you want to achieve? you may need to use systemLog option on Docker.
@ozlerhakan What's the equivalent of this on a Mac? I'm trying to use a config file, but I thought we couldn't do mounts with VirtualBox?
$ docker run --name mongo -d -v //c/Users/Hakan/config:/mongodb mongo:3.2 mongod -f //mongodb/mongod.conf
I just tried this: docker run -d -v /tmp/mongodb:/mongodb -p 27017:27017 --name mongodb mongo:3.2.4 mongod -f /mongodb/mongod.conf
cat /tmp/mongodb/mongod.conf
storage:
dbPath: /data/db
directoryPerDB: true
journal:
enabled: true
engine: wiredTiger
net:
port: 27017
Container crashes with this in the log: Error reading config file: No such file or directory
@jeremypumphrey, you can do mounts, but not on the data since the Virtual Box shared folder does not work for mongo. In order to mount the config file, you need to make sure it is readable by the mongodb user in the container; uid 999 I believe.
The file is 644 on my local system. How do I do a chown in the container while still using the official mongo docker build? I don't have a Dockerfile to add a step to without breaking out into my own version right?
I moved it out of /tmp to under my home directory and it worked on my Mac. Thanks.
docker run -d -v ~/git/match-docker/Dockerfiles/mongodb:/mongodb -p 27017:27017 --name mongodb mongo:3.2.4 mongod -f /mongodb/mongod.conf
Seems like using custom config file with official mongo image is tricky.
@ViktorKonsta not sure how you mean -- for simple configuration, you can just provide the flags you need directly to the image (docker run mongo --xyz), for more complex configuration, you either bind-mount your desired configuration file or use a simple Dockerfile and COPY with -f /path/to/mounted/or/copied/mongod.conf
For some reason I should use MongoDb with VERSION:3.0.1
Now : 2016-09-13 17:42:06
copyed form my answer in stackoverflow(when you google "docker mongo configure" you mayfind it twice)
I can't use all the solution above.
That is what I found:
#first step: run mongo 3.0.1 without conf
docker run --name testmongo -p 27017:27017 -d mongo:3.0.1
#sec step:
docker exec -it mongotest cat /entrypoint.sh
#!/bin/bash
set -e
if [ "${1:0:1}" = '-' ]; then
set -- mongod "$@"
fi
if [ "$1" = 'mongod' ]; then
chown -R mongodb /data/db
numa='numactl --interleave=all'
if $numa true &> /dev/null; then
set -- $numa "$@"
fi
exec gosu mongodb "$@"
fi
exec "$@"
So,now we know when docker run, we should't type mongod:
docker run --name mongo -d -v your/host/dir:/container/dir mongo:3.0.1 -f /container/dir/mongod.conf
docker run -d -v /srv/dockervolume/mongo/mongodata/db-tillvaxt:/data/db -v /srv/dockervolume/mongo/mongod.conf:/etc/mongod.conf --name mongo-tillvaxt -h mongo mongo:latest, isn't loading my conf file.
Also tried:
docker run -d -v /srv/dockervolume/mongo/mongodata/db-tillvaxt:/data/db -v /srv/dockervolume/mongo/mongod.conf:/etc/mongod.conf --name mongo-tillvaxt -h mongo mongo:latest -f /etc/mongod.conf
The container doesn't start though.
These are the valid commands (in 1.13) working on my mac:
docker container run --rm -v $(PWD)/config/mongod.conf:/etc/mongod.conf mongo:3.4 mongod -f /etc/mongod.conf
docker container run --rm -v $(PWD)/config/mongod.conf:/etc/mongod.conf mongo:3.4 -f /etc/mongod.conf
This
docker run -d --restart=always -p 27017:27017 -v ~/mongo/db:/data/db mongo:latest mongod -f /data/db/mongod.conf
gives me these errors.
2017-02-10T00:36:32.133+0000 I CONTROL [initandlisten] options: { config: "/data/db/mongod.conf", net: { port: 27017 }, storage: { dbPath: "/data/db", directoryPerDB: true, engine: "wiredTiger", journal: { enabled: true } } }
2017-02-10T00:36:32.166+0000 I STORAGE [initandlisten] exception in initAndListen: 72 Requested option conflicts with current storage engine option for directoryPerDB; you requested true but the current server storage is already set to false and cannot be changed, terminating
@ozitraveller according to that error message, your mongod.conf is specifying conflicting settings for directoryPerDB and wiredTiger
Thanks tianon that's now fixed.
Where is the log file and what is it called?
Ok I need to do this:
auditLog:
destination:
format:
path:
filter:
Found it and done! :)
Unrecognized option: auditLog.path
I don't see why the path is wrong? It's the same folder as the conf file.
storage:
dbPath: data/db
engine: wiredTiger
journal:
enabled: true
auditLog:
destination: file
format: BSON
path: data/db/centresLog.bson
filter: '{ "param.ns": "CentresDb.Centres", "param.command": { $in: [ "insert", "delete", "update", "findandmodify" ] } }'
net:
port: 27017
I'd suggest making the path absolute (ie, start with "/", as in
"/data/db/centresLog.bson")
I've tried both already and neither worked. But I'll try them both again.
Would quotes make any difference?
Cheers
I'm running docker 1.12.2 on centos.
Having the auditlog stanza in the config file causes the container to restart.
]$ docker logs f007
Unrecognized option: auditLog.path
try 'mongod --help' for more information
Unrecognized option: auditLog.path
try 'mongod --help' for more information
Unrecognized option: auditLog.path
try 'mongod --help' for more information
Unrecognized option: auditLog.path
try 'mongod --help' for more information
Unrecognized option: auditLog.path
try 'mongod --help' for more information
Unrecognized option: auditLog.path
try 'mongod --help' for more information
Unrecognized option: auditLog.path
try 'mongod --help' for more information
Unrecognized option: auditLog.path
try 'mongod --help' for more information
Closing old issue. Debugging MongoDB config should be done at one of the places listed on the MongoDB Docs. Feel free to comment on further troubleshooting if you feel this was closed in error or on the solution to help users running into the same problem.
To add a custom config file, the simplest solution is to run the container with a file mounted in; this can be adapted to be used via docker-compose or a custom Dockerfile that builds the config in.
$ # assuming `/your/host/dir/` contains `mongo.conf`
$ docker run --name mongo -d -v /your/host/dir:/container/dir mongo:3.4 -f /container/dir/mongod.conf
Most helpful comment
@ozlerhakan thanks reply.
I find the reason, my mongod.conf include systemLog config option, I try comment it, the command works. but I do not know why.