How to create user in mongodb with docker-compose

后端 未结 8 1183
天命终不由人
天命终不由人 2020-12-23 20:28

I\'m trying to create some kind of script that will create a docker with mongodb and automatically create a user.

I can usually manage my docker images with docker-c

8条回答
  •  既然无缘
    2020-12-23 21:08

    EDIT: tutumcloud repository is deprecated and no longer maintained, see other answers

    I suggest that you use environment variables to set mongo user, database and password. tutum (owned by Docker) published a very good image

    https://github.com/tutumcloud/mongodb

    docker run -d -p 27017:27017 -p 28017:28017 -e MONGODB_USER="user" -e MONGODB_DATABASE="mydatabase" -e MONGODB_PASS="mypass" tutum/mongodb
    

    You may convert these variables into docker-compose environments variables. You don't have to hard code it.

    environment:
        MONGODB_USER: "${db_user_env}"
        MONGODB_DATABASE: "${dbname_env}"
        MONGODB_PASS: "${db_pass}"
    

    This configuration will read from your session's environment variables.

提交回复
热议问题