permissions on /keyfile are too open
ThinhVu opened this issue · 2 comments
ThinhVu commented
The command I tried is:
docker run --rm --name mongodb \
-e MONGO_INITDB_ROOT_USERNAME=admin \
-e MONGO_INITDB_ROOT_PASSWORD=your_admin_password \
-e MONGO_INITDB_DATABASE=mydatabase \
-v mongodb-keyfile:/keyfile \
mongo:latest --auth --keyFile /keyfile
Anyone know how to get rid of this issue?
ThinhVu commented
After a few hours search over the internet, I figured it out.
The docker run with mongodb user.
So:
- I need to add new
mongodb
user - Then add chmod of keyfile to 400.
- Then create docker volume to mount the mongo /data/db
- chown the docker volume for mongo /data/db with mongodb user
The final command:
docker run -d --rm --name mongodb \
--user 1001:1001 \
-e MONGO_INITDB_ROOT_USERNAME=admin \
-e MONGO_INITDB_ROOT_PASSWORD=your_admin_password \
-e MONGO_INITDB_DATABASE=mydatabase \
-v /var/lib/docker/volumes/mongo-data/_data:/data/db \
-v /var/lib/docker/volumes/mongodb-keyfile/_data/keyfile:/keyfile \
-p 27017:27017 \
mongo:latest --auth --replSet "rs0" --keyFile /keyfile