Setup rails project using Docker

Install Docker
https://docs.docker.com/engine/installation/mac/

Install Docker toolbox
https://www.docker.com/products/docker-toolbox

Create necessary files

mkdir docker && cd docker
touch Dockerfile
touch Gemfile
touch Gemfile.lock
touch docker-compose.yml

Dockerfile

FROM ruby:2.3.3
RUN curl -fsSL https://get.docker.com/gpg | apt-key add -
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /ror
WORKDIR /ror
COPY Gemfile /ror/Gemfile
COPY Gemfile.lock /ror/Gemfile.lock
RUN bundle install
ADD . /ror

Gemfile

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

docker-compose.yml
web, db you can using any name, image(s) you can find at https://hub.docker.com/search
web is your app name

version: '2'
services:
  db:
    image: postgres
  web:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
      - .:/ror
    ports:
      - "3000:3000"
    depends_on:
      - db

Init rails project

docker-compose run web rails new . --force --database=postgresql --skip-bundle

config/database.yml

development: &default
  adapter: postgresql
  database: docker_development
  username: postgres
  password: ''
  host: db

test:
  <<: *default
  database: docker_test

Start web app on Docker

docker-compose build
docker-compose up

Create db in another tab
web is your app name (docker-compose.yml)

cd docker
docker-compose run web bundle exec rake db:create

Enjoy
http://localhost:3000