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)

  • Docker-compose not passing environment variable to container
  • Docker Compose Link (Alias)
  • How to play sound in a docker container
  • Why didn't docker copy files to the mounted directory?
  • Docker: correct way of persisting container data to host
  • Docker instance cannot run images anymore and unable to reclaim free space
  • 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.

  • Gradle Docker plugin broken pipe on osx
  • How should I create Dockerfile to run multiple services through docker-compose?
  • Is docker phasing out some sites and services or something?
  • Connect to Docker API from Windows to external server
  • Connecting from php to mysql in Docker
  • `initialize': the scheme postgres does not accept registry part: postgres:@ (or bad hostname?) (URI::InvalidURIError) with Docker
  • 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.