Syntax issue with adding creating a mongodb and user with roles

I’ve started building my first docker container for a mongodb with auth.

I have a python script that fetches credentials from our password safe and makes them available for a bash script which then sets up the admin db and users.

  • Docker Devmapper space issue - increase size
  • When to use --hostname in docker?
  • Nginx can't talk to PHP-fpm in Docker
  • How to continue using docker container after startup application exit?
  • Docker unable to process Dockerfile
  • pip install django-allauth UnicodeDecodeError
  • I use a RUN command for the python script and that is fine.

    The bash script runs perfectly when I log into the container and run it.

    However, it should run as part of a CMD surely?

    Dockerfile extract:

    ADD /
    ADD /
    RUN chmod +x /
    RUN chmod +x /
    RUN python / <user> <password>
    CMD ["/bin/bash","/"]

    Bash script

    mongod --auth
    source mongodb_credentials.txt
    # Wait for MongoDB to boot
    while [[ RET -ne 0 ]]; do
        echo "=> Waiting for confirmation of MongoDB service startup..."
        sleep 5
        mongo admin --eval "help" >/dev/null 2>&1
    echo "=> Creating admin user"
    mongo admin --eval "db.createUser({user: '$MONGO_ADMIN_USER', pwd: '$MONGO_ADMIN_PASSWORD', roles:[{role:'userAdminAnyDatabase',db:'admin'}]});"
    sleep 3
    echo "=> Creating IawApi user"
    mongo admin -u $MONGO_ADMIN_USER -p $MONGO_ADMIN_PASSWORD --eval "db.createUser({user: '$MONGO_IAWAPI_USER', pwd: '$MONGO_IAWAPI_PASSWORD', roles:[{role:'dbOwner',db:'IawApi'}]});"
    echo "=> Creating vpnDebugger user"
    mongo admin -u $MONGO_ADMIN_USER -p $MONGO_ADMIN_PASSWORD --eval "db.createUser({user: '$MONGO_VPNDEBUGGER_USER', pwd: '$MONGO_VPNDEBUGGER_PASSWORD', roles:[{role:'dbOwner',db:'vpnDebugger'}]});"
    echo "Done!"
    # delete anything that can be used to gain access to credentials
    rm -f mongodb_credentials.txt
    rm -f

  • How to write commands with multiple lines in Dockerfile while preserving the new lines?
  • Get Swarm node IP address from a container using API?
  • How to setup heroku app locally using docker?
  • Server and client network apps simulated in one machine
  • Pushing a Docker image with gcloud failed
  • How to monitor Nodejs app running on Kubernetes
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.