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:

pg:
  image: docker-index.my.com/postgres
  ports:
    - 5432
redis:
  image: docker-index.my.com/redis
  ports:
    - 6379
mongodb:
  image: docker-index.my.com/mongodb
  ports:
    - 27017
app:
  build: .
  command: bundle exec rails s
  volumes:
    - .:/beesor
  ports:
    - 3000:3000
  links:
    - pg
    - redis
    - mongodb
  environment:
    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)

  • What are the correct Permissions for docker in docker as another user?
  • Stop recently started container in docker?
  • How to include modified configuration files in a docker image?
  • Running Ejabberd Deis/Docker
  • Docker: using container with headless Selenium Chromedriver
  • “Exception: Non-zero exit code: 1” in Automated Build on Docker Hub
  • Dockerfile contents:

    # DOCKER-VERSION 0.10.0
    FROM docker-index.my.com/ruby:1.9.3
    MAINTAINER my.com
    
    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.

  • Running collectstatic on Dokku doesn't copy files
  • Docker dynamic load balancing with Nginx
  • How to install a non-distro package inside Docker without wasting space?
  • How do you get a VPC Endpoint to work in a Docker container?
  • Specify bolt port for a neo4j docker container
  • docker “--volumes-from” files not updating to target containers
  • 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.