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)

  • Establish PSSession to Windows docker container from remote machine (not container host)
  • Cannot install gems from git in dockerized rails app
  • How to use multiple base images to build a docker image
  • How to prevent access to docker socket form within a container
  • In Docker, what's the difference between a container and an image?
  • Setting docker with nginx and php5
  • 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.

  • Rails Atomicity problems?
  • Gitlab 500 page after upgrading a gitlab setup with two-factor login
  • Docker Registry and Basic Auth
  • trouble with running e2e on bitbucket pipeline
  • Get dockerfile / docker commands from docker image
  • Using Kubernetes with an Artifactory/Nginx proxy
  • 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.