Skip to content

Instantly share code, notes, and snippets.

@dineshsprabu
Last active April 25, 2017 10:16
Show Gist options
  • Save dineshsprabu/9d96a9ef1cd90d1e3c4e1fcf58a75cf5 to your computer and use it in GitHub Desktop.
Save dineshsprabu/9d96a9ef1cd90d1e3c4e1fcf58a75cf5 to your computer and use it in GitHub Desktop.
[Docker] Creating new docker container image for a rails app

New Rails app with Mysql in Docker

Create a Gemfile with content

source 'source 'https://rubygems.org'
gem 'rails', '4.2.7.1'

Create an empty file 'Gemfile.lock'

Create file 'DockerFile'.

Create file 'docker-compose.yml'

Add DockerFile below lines for setting up the app.

From ruby:2.3.0
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /noteapp
WORKDIR /noteapp
ADD Gemfile /noteapp/Gemfile
ADD Gemfile.lock /noteapp/Gemfile.lock
RUN bundle install
ADD ./noteapp

Add the docker compose file https://gist.github.com/dineshsprabu/973a1a723fab711138c7c96bd2ba0264. Check the contents to understand.

Run 'docker-compose run app rails new . --force --database=mysql --skip-bundle'.

This will install the rails new app.

Now edit the database.yml file and set database configuration the use environment variable configured on docker-compose.yml.

Now run 'docker-compose build' and see the container being created.

Run 'docker-compose run --rm app rake db:migrate' for db migrate.

We can run any rake task like same above.

Run 'docker-compose up' for bringing up the container.

Now we should be able to access http://localhost:3001 as per our compose file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment