Docker rails migrations

I’m trying to get running my rails application with docker and fig, it counts with a redis server, mongodb, postgres, and nginx as well,
Here is how my fig.yml looks like:

    - 5432
    - 6379
    - 27017
  build: .
  command: bundle exec rails s
    - .:/beesor
    - 3000:3000
    - pg
    - redis
    - mongodb
    RAILS_ENV: production

Everything works ok till the moment of starting app, as rails initializers hooks on server starts then I got errors regarding the database connection, the database does not exists! of course because it was not created on the Dockerfile (see below)

  • Running many docker instances on Google cloud with different command-line parameters
  • Starting multiple services inside Docker container
  • How to get Docker to run on a Windows System behind a corporate firewall?
  • ps command doesn't work in docker container
  • Apache Kafka IO errors
  • Bluemix: local Docker daemon is not reachable to authenticate it
  • Dockerfile contents:

    # DOCKER-VERSION 0.10.0
    RUN apt-get update -qq && apt-get install -y git-core xvfb curl nodejs libqt4-dev libgtk2.0-0 libgtkmm-3.0-1 libnotify4 sqlite3 libsqlite3-dev graphicsmagick imagemagick subversion libpq-dev libxml2-dev libxslt-dev git build-essential
    RUN mkdir /my_app
    WORKDIR /my_app
    RUN gem install bundler
    ADD Gemfile /my_app/Gemfile
    ADD Gemfile.lock /my_app/Gemfile.lock
    RUN bundle install
    RUN bundle pack --all
    ADD . /my_app

    I don’t see a place where I can put the rake db:create db:migrate db:seed commands!, if I put them at the end of the Dockerfile then when fig tries to build app it complains about the database server does not exits, (in the time that fig builds app container the other containers are not started), and I could not fix this changing the order on the fig.yml,
    I’m facing egg-chicken problem here, who can I get this working?

    I’m sure that all the links work perfectly so the problem is more about orchestration of scripts.

  • What is a reliable way to change PostgreSQL configuration, especially move its data directory in a script?
  • Docker + Nodejs + Private Repo + Private NPM Module - Access Problems
  • Docker-swarm automatically pulling missing image from private docker-registry
  • Access Host redis database from docker conatiner
  • Container healthcheck status via tasks json
  • what is 'z' flag in docker container's volumes-from option?
  • One Solution collect form web for “Docker rails migrations”

    Found the solution!:

    I created a rake task to wrap what I need, it runs migrations, seeds, and starts the rails server, so the fix is to change the command on fig by this one:

    command: rake my_app:setup

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