How to enable authentication on MongoDB through Docker?

后端 未结 10 2128
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 18:53

I want to spin-up a docker for mongodb:latest but allow only certain user(s) to access certain db(s) (i.e. enable --auth). No one else should acces

10条回答
  •  执念已碎
    2020-11-29 19:05

    The Dockerfile for the official mongo image is here. The default command is mongod but you can override to add the --auth switch assuming user's are already configured.

    docker run -d .... mongodb:latest mongod --auth
    

    If the user has to be created then you need to volume mount a startup script into /entrypoint.sh to replace the default startup script and then have that script create users and start mongo with the auth switch.

    docker run -d .... -v $PWD/my_custom_script.sh:/entrypoint.sh mongodb:latest
    

提交回复
热议问题