Docker Community Forums

Share and learn in the Docker community.

ERROR:Permission denied, terminating (mongoDB)

Hi everyone hope you are having a nice day i need help with on junior error in docker im using deepin 15.11 (debian distribuition) so im trying to make a mongodb container, the example “docker run hello-world” works well but when i try with “docker run -d --name somename mongo” immediately the status of the container say Exited (100) so i see the logs and seems like this container needs permissions i did thing like "chmod -R 777 " in /var/lib/docker/volumes/ also /var/run/docker/ and nothing work, heeeeeeelp please i think my S.O need some configuration cause is based in debian

$docker logs bd
2020-07-15T18:22:55.292+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols ‘none’
2020-07-15T18:22:55.293+0000 W ASIO [main] No TransportLayer configured during NetworkInterface startup
2020-07-15T18:22:55.294+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=aed83febdda7
2020-07-15T18:22:55.294+0000 I CONTROL [initandlisten] db version v4.2.8
2020-07-15T18:22:55.294+0000 I CONTROL [initandlisten] git version: 43d25964249164d76d5e04dd6cf38f6111e21f5f
2020-07-15T18:22:55.294+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
2020-07-15T18:22:55.294+0000 I CONTROL [initandlisten] allocator: tcmalloc
2020-07-15T18:22:55.294+0000 I CONTROL [initandlisten] modules: none
2020-07-15T18:22:55.294+0000 I CONTROL [initandlisten] build environment:
2020-07-15T18:22:55.294+0000 I CONTROL [initandlisten] distmod: ubuntu1804
2020-07-15T18:22:55.294+0000 I CONTROL [initandlisten] distarch: x86_64
2020-07-15T18:22:55.294+0000 I CONTROL [initandlisten] target_arch: x86_64
2020-07-15T18:22:55.294+0000 I CONTROL [initandlisten] options: { net: { bindIp: “*” } }
2020-07-15T18:22:55.294+0000 I STORAGE [initandlisten] exception in initAndListen std::exception: open: Permission denied, terminating
2020-07-15T18:22:55.294+0000 I CONTROL [initandlisten] now exiting
2020-07-15T18:22:55.294+0000 I CONTROL [initandlisten] shutting down with code:100

$docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
aed83febdda7 mongo “docker-entrypoint.s…” 42 minutes ago Exited (100) 42 minutes ago bd

If you now command:

sudo chown -R mongodb:mongodb /home/user/mongodb
sudo service mongod restart
It will work!

Problems here was that you gave command sudo mongod --dbpath /home/user/mongodb/data/ what created ROOT ownded files to that /home/user/mongodb/data/ directory and your “normal” mongodb user don’t have right to overwrite those.

So, NEVER start your mongod as root OR if you do so, remember reset ownership of those data files back to mongodb.