offical mongo docker image cannot use custom file via volumen - mongodb

I am trying simply to use mongo with custom configuration file placed in my host machine. I obtain 100 error code, I tested this in debian 10 and on a windows 10 machine (docker desktop). I think that its a permission issue, may be mongo has not permission to use those files.
docker-compose.yml
version: "3.7"
services:
mongod:
image: mongo:4.1.13
# restart: always
ports:
- "27017:27017"
volumes:
- ./config/mongo/mongod.conf:/etc/mongod.conf
- ./data/mongo:/data/db
# - ./log/mongo:/var/log/mongodb
entrypoint: ["mongod","--config","/etc/mongod.conf","--verbose"]
mongod.conf (default)
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
Error:
This, this image does not create a log file under /var/log/mongodb.

Your docker-compose.yml and mongod.conf has inconsistent options:
docker-compose.yml specifies /data/db as a folder for DB files, but mongod.conf tries to use dbPath: /var/lib/mongodb (which is missing in your container). Fix your mongod.conf to point to /data/db/ folder and it should fix your error.
To debug such kind of error, your can run your image (mongo) by hand (docker run ...) with bash, instead of using docker-compose and you will be able to see all error in logs.

Related

/var/run/mongodb/ folder is deleted every system reboot

Every time I restart the system the "/var/run/mongodb/" folder is deleted and mongodb cannot be started. Here is my mongod.conf file:
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# engine:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 38512
bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
security:
authorization: enabled
keyFile: /var/lib/mongodb/replica_set_key
#operationProfiling:
replication:
replSetName: "dbr"
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
I am using Ubuntu 20.04.
I first tried this solution https://stackoverflow.com/a/54755924/14971470 for the
"ERROR: Cannot write pid file to {path_string}: {errAndStr_second}","attr":{"path_string":"/var/run/mongodb/mongod.pid","errAndStr_second":"No such file or directory""
error and it fixed it.
But every time I restart the system, the "/var/run/mongodb/" folder is deleted again and mongodb can't be started.

Mongodb Status failed after editing .conf file

I want to enable the security by using creating a user in admin db. And I created that user after that I will edit mongodb conf file. After that I'm facing some issue while connecting that I'm not able to connect with the shell. After google I reached to a question with accepted answer. I follow that question and did all the things given in the answer then still facing issue while connecting with mongo shell. I'm pasting mongo conf file. Please let me know if there is any changes.
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
#security:
security.authorization: enabled
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
security:
authorization: enabled
Should be fine. And don't forget to restart the server.

Mongo auth fails to login when using mongod.conf

So this is the weirdest thing.
I have two centOS 7 servers running mongo. I now wanted to enforce authentication so I added the security.authorization: enabled to the mongod.conf file.
I already have a user on database "buzzztv".
So when I ran mongod --conf /etc/mongod.conf on the first server everything went fine.
Then I did the exact same thing on the second server and whenever I try to connect with one of the users I get the following error:
connecting to: mongodb://127.0.0.1:27017/?authSource=buzzztv&compressors=disabled&gssapiServiceName=mongodb
2020-02-20T13:02:35.166+0000 E QUERY [js] Error: Authentication failed. :
connect#src/mongo/shell/mongo.js:341:17
#(connect):2:6
2020-02-20T13:02:35.168+0000 F - [main] exception: connect failed
2020-02-20T13:02:35.168+0000 E - [main] exiting with code 1
Now if I run mongod --fork --logpath /var/log/mongodb/mongod.log --auth the login works perfectly fine.
So obiously I could just run this command, but I want to use the mongod.conf.
Here is my mongod.conf file, I checked and it is a perfect copy of the file from the server in which it does work.
Any ideas?
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0 # 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
security:
authorization: enabled
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
So after several hurtful hours of looking into it, I neede to change the
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
Apparently something was wrong with my /var/lib/mongo so I backed up the data, and created a new folder /var/lib/mongodb
Then edited the mongod.conf file to:
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
Then it all worked fine. Now I'll just re-create the users and re-insert all the data and I'm good to go.
Hope this saves someone the wasteful hours I've lost

Can you use a network alias in a mongo configuration file when using bindIp?

I am trying to get my mongodb container to listen to my API trying to connect but it won't start up. As I've understood using bindIpAll and setting it to true isn't ideal so I created a network in my compose file to get some communication between them.
Here is my configuration of that in my docker compose file:
version: '3'
networks:
backend:
services:
unit:
image: nginx/unit:1.8.0-full
networks:
backend:
database:
image: mongo:4.0-xenial
entrypoint: mongod --config /etc/mongod.conf
ports:
- 27000:27017
depends_on:
- unit
volumes:
- ./db/config/mongod.conf:/etc/mongod.conf
- mongoData:/data/db/
- mongoLog:/var/log/mongodb/
- mongoPID:/var/run/mongodb/
networks:
backend:
I included the unit service for understanding of the following block. In the following block I've tried to set the aliases to the networks, as well as using the actual name of the network and I haven't gotten a solution I also tried using the service's name. This is the net section of my mongo config.
net:
port: 27017
bindIp: unit #backend network defined in the docker-compose file
Like I mentioned the service doesn't start up, mongo gives me the following message:
Failed to set up listener: SocketException: Cannot assign requested address
If I use bindIpAll in the config it all seems to work okay but as I've stated I am under the impression (perhaps incorrectly) that that's the wrong approach.
Here is my entire mongo.conf file:
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /data/db
journal:
enabled: true
# how the process runs
processManagement:
fork: false # run in the background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27017
#bindIpAll: true
bindIp: unit #backend network defined in the docker-compose file
security:
authorization: "enabled"
setParameter:
authenticationMechanisms: "SCRAM-SHA-256"

Error while starting Mongod with config file option

I am not able to start mongod servers with replication using config file.
when issue the command
mongod --config /etc/mongod1.conf
throws an error-
Unrecognized option: replSet
Unrecognized option: oplogSizeMB
MongoDB Version: 3.0
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo/test
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
# network interfaces
net:
port: 27030
# bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
#security:
#operationProfiling:
replication:
replSet: testrep
oplogSizeMB: 1024
#sharding:
## Enterprise-Only Options
please help me.
Just ident replSet and oplogSizeMB lines two spaces to the right. That's the thing with yaml