Docker + supervisord: how to initialize services (mongo & elasticmq)?

I am using docker with supervisord to create tests environments with some services we use, as recommended in docker doc. The basic configuration for the services is running, I can /bin/bash the container and use it from my application without problem (with some initialisation by hand)

Now I need to add some objects to mongo: basic data to test the applications. Is there a recommended way to do that? Using a bash script I would do:

  • Docker run command with environment variables
  • Dockerfile with nesting via non-master branches
  • docker build fails in jhipster
  • Elasticsearch deployment on google app engine flex
  • Were are the docker Remote API logs stored?
  • INFO hdfs.HDFSEventSink: Writer callback called
  • ...
    # Launch Mongodb
    /usr/bin/mongod &
    sleep 3;
    mongo --eval "db.getSiblingDB('MyDDBB') {...} )";

    but that bash is what I’m trying to get rid of. The use of elasticmq is exactly the same: I need to run something that creates some queues when te container starts running, so probably one solution fits both.

    I’m open to different solutions (change the supervisor?)

  • Cannot dump a database in a mysql container
  • Collectd pushes the actual host system metrics to graphite instead of the docker container's restricted system metrics
  • If I use EXPOSE $PORT in a Dockerfile, can I un-expose the port it when I use `docker run`?
  • Docker limit memory usage is not working
  • (spotify) Maven docker builder for Java
  • How to run nginx with docker container?
  • One Solution collect form web for “Docker + supervisord: how to initialize services (mongo & elasticmq)?”

    I don’t know if you’re still looking for a perfect solution, this might not be the one but it works for me:

    In my docker-compose.yml I set it so it uses my own entrypoint:

        image: mongo:2.4
        entrypoint: /code/devops/current/docker/dev/mongodb/
            - ~/Workspaces/project/devops/:/code/devops/current/

    And my entrypoint first starts mongod in the background, execute a javascript file kill mongo and start it as the main process, like so:

    mongod --noprealloc --smallfiles &
    sleep 3
    echo "--> init"
    mongo /code/devops/current/docker/dev/mongodb/init.js
    echo "--> init [DONE]"
    kill $PID
    sleep 3
    mongod --noprealloc --smallfiles --auth

    In the init.js I make sure my tables are created, and have the user required to access it, so it’s a bunch of:

    db = db.getMongo().getDB('mydbname')
    db.addUser({user: "devuser", pwd: "mypassword", roles: ["readWrite"]})

    So I imagine you have to adapt pretty much everything but it gets me going for my dev environment 😉

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.