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 for Mac cannot access containers outside of host
  • “Could not delete ./” when I use composer in docker
  • Changing a Docker container
  • Add -f parameter when running Docker Toolbox
  • Understanding “VOLUME” instruction in DockerFile
  • Artifactory the web interface is not accessible
  • I use a RUN command for the python script and that is fine.

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

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

    Dockerfile extract:

    ADD set_mongo_passwords.py /
    ADD run.sh /
    
    RUN chmod +x /run.sh
    RUN chmod +x /set_mongo_passwords.py
    
    RUN python /set_mongo_passwords.py <user> <password>
    CMD ["/bin/bash","/run.sh"]
    

    Bash script

    #!/bin/sh
    
    mongod --auth
    
    source mongodb_credentials.txt
    
    # Wait for MongoDB to boot
    RET=1
    while [[ RET -ne 0 ]]; do
        echo "=> Waiting for confirmation of MongoDB service startup..."
        sleep 5
        mongo admin --eval "help" >/dev/null 2>&1
        RET=$?
    done
    
    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 set_mongo_passwords.py
    

  • Keep DNS resolution of a stopped docker container in docker DNS
  • Start DB2 server in docker container on a specific date without changing host date
  • Volume is not shared between nodes of Docker Swarm
  • Remove /bin/busybox at build time
  • Gitlab CI Runner, DigitalOcean and Docker Compose
  • marathon + mesos + networking + docker-compose
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.