MongoDB docker error: Failed to open /var/log/mongodb/mongod.log
Asked Answered
D

4

6

I am trying to run a docker instance and keep coming across this server. Here is what I get after trying to setup the instance:

Starting instance ... done
Attaching to instance
instance   | {"t":{"$date":"2020-12-08T14:06:42.033Z"},"s":"F",  "c":"CONTROL",  "id":20574,   "ctx":"main","msg":"Error during global initialization","attr":{"error":{"code":38,"codeName":"FileNotOpen","errmsg":"Failed to open /var/log/mongodb/mongod.log"}}}
instance exited with code 1

The file permissions are:

$ ls -l /var/log/mongodb/mongod.log
-rwxr-xr-x 1 mongodb mongodb 0 Dec  8 19:32 /var/log/mongodb/mongod.log

What else I've tried:

  1. Shutting down and removing all containers and removing the build-cache
  2. Removing all .sock files from /var/lib/mongodb
  3. uninstalling and reinstalling docker.
  4. Checking if the ports on my .conf file are unoccupied.
  5. Adding user mongodb as owner and group to both the lib and log mongodb folders.

I am not sure anymore where this issue is coming from. Would like to have some alternate solutions to this.

Declaim answered 8/12, 2020 at 14:18 Comment(1)
How did you fix it? I am facing the same issueOberhausen
B
3

I had the same issue. I think the permission could be wrong for the folder. Try setting the permission 777 for log and data

Bazar answered 18/12, 2020 at 14:13 Comment(5)
facing same issue.I didn't helped meCockswain
chmod 777 -R /var/log/mongodb/ Worked for mePassport
chmod 777 -R /var/log/mongodb/ Worked for me tooLeenaleeper
i got the error like $ chmod 777 -R mongod.cfg. chmod: changing permissions of 'mongod.cfg': Permission deniedDemocritus
@DarpanRajput just use sudoBourg
N
1

If your mongodb was working well & suddenly it stopped working, then it can possible be an error related to permission. Below commands can be used to get back mongodb into running state -

  1. check the permission of /var/lib/mongodb & /var/log/mongodb & match it with the official installtion guide.
  2. try to make permission as same as guided by the official site.
  3. If you are unable to resolve it that way or want a quick fix, you can do the following. it will definitely resolve the issue -
sudo chmod 777 -R /var/log/mongodb // not good from safety perspective.

sudo chmod 777 -R /var/lib/mongodb // not good from safety perspective. 

sudo rm -rf /tmp/mongod-*.sock

and them you can simply restart the server & check the status with below commands -

sudo service mongod restart 

sudo service mongod status 

 or 

sudo systemctl restart mongod 

sudo systemctl status mongod

If this answer works for you, please vote it.

Nosepiece answered 31/10, 2022 at 12:42 Comment(0)
K
1

I went thru a lot of posts, changed permissions, followed this one and tried it all:

Permission denied to read file owned by user

I even followed the tutorial at mongo step by step:

https://www.mongodb.com/docs/manual/tutorial/deploy-replica-set-with-keyfile-access-control/

And nothing worked for me.

This one:

sudo chown mongodb mongo.key

Didnt work either, but at the end, I thought of restarting the server, and after

sudo service mongod start

and it all worked.

I have no answer why this worked, but a restart on my three servers worked just perfect.

And here's my mongod.conf

security:
  authorization: enabled
  keyFile: /var/lib/mongodb/mongo.key

Thanks.

Kirksey answered 28/2, 2023 at 5:28 Comment(0)
S
0

I won't recommend using chmod 777 for fixing this issue. Rather change the ownership to MongoDB:

chown mongodb:mongodb /var/log/mongodb/mongod.log

Then you can start the MongoDB service:

$ sudo systemctl start mongod
$ sudo systemctl status mongod
● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
     Active: active (running) since Wed 2024-10-09 18:50:16 +06; 1s ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 162606 (mongod)
     Memory: 79.3M
        CPU: 624ms
     CGroup: /system.slice/mongod.service
             └─162606 /usr/bin/mongod --config /etc/mongod.conf

Oct 09 18:50:16 pop-os systemd[1]: Started MongoDB Database Server.
Simasimah answered 9/10 at 12:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.