Skip to content

Instantly share code, notes, and snippets.

@pgericson
Created March 30, 2016 15:48
Show Gist options
  • Save pgericson/cac0644b683f8fbf9d3a769234b5d1fc to your computer and use it in GitHub Desktop.
Save pgericson/cac0644b683f8fbf9d3a769234b5d1fc to your computer and use it in GitHub Desktop.
Docker setup for rails 4.0+ app with empty bundle container for caching with Vagrant for OS X

README

Development Environments

Linux

Use docker-compose docker-compose up to start the different services in the docker-compose.yml file

First time use

  • docker-compose run web bundle exec rails db:create
  • docker-compose run web bundle exec rails db:migrate

Mac

Mac needs a virtual environment, here using docker-osx-dev. Because vagrant was not stable enough for syncing files. run

curl -o /usr/local/bin/docker-osx-dev https://raw.githubusercontent.com/brikis98/docker-osx-dev/master/src/docker-osx-dev
chmod +x /usr/local/bin/docker-osx-dev
docker-osx-dev install

Add eval "$(boot2docker shellinit)" to your ~/.bashrc file, this will give you dockerhost hostname in the root folder docker-osx-dev this will sync the files from host machine to guest VM in a new tab run docker-compose up

version: '2'
services:
db:
image: postgres
web:
build: .
command: ./script_start
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
# This tells the webcontainer to mount the `bundle` images'
# /bundle volumne to the `web` containers /bundle path.
volumes_from:
- box
box:
# 'image' will vary depending on your docker-compose
# project name. you may need to run docker-compose build web
# before this works
image: busybox
volumes:
- /box
FROM ruby:2.2.3
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
ENV APP_HOME /myapp
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
ENV BUNDLE_PATH /box
ADD . $APP_HOME
#!/bin/bash
bundle check || bundle install
# to remove the boring error messaged called server is still running error
rm tmp/pids/server.pid
# use bundle exec and start rails on port 3000
bundle exec rails s -p 3000 -b 0.0.0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment