Mongo docker with volume get error

对着背影说爱祢 提交于 2021-02-08 07:26:20

问题


After running docker run --name mongo -p 27017:27017 -v ~/Documents/store/mongo/:/data/db -d mongo --smallfiles

[initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating

In store directory, ls -l

drwxr-xr-x  4 MeoBeoI  staff  136 Dec  8 17:11 mongo
drwxr-xr-x  2 MeoBeoI  staff   68 Dec  9 10:20 redis

I use OSX 10.11.1


回答1:


Looking at the mongo Dockerfile:

  • a user mongodb is created
  • /data/db is created and protected for mongodb:mongodb

So try and make sure to start your container with that user:

docker run --user mongodb ...

If that is not working, then fallback to the original docker run command (which runs as root by default) and define run.sh (that needs to be copied in your own image) which will:

  • do the right chown -R mongodb:mongodb /data/db
  • call entrypoint.sh mongod

That is:

docker run ... run.sh

That would be an approach similar to issue 7198 (Make uid & gid configurable for shared volumes).



来源:https://stackoverflow.com/questions/34172338/mongo-docker-with-volume-get-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!