Skip to content

Instantly share code, notes, and snippets.

@peterkappus
Created July 3, 2017 21:56
Show Gist options
  • Save peterkappus/1d9e1e6f1982c534c3acd145850f3f40 to your computer and use it in GitHub Desktop.
Save peterkappus/1d9e1e6f1982c534c3acd145850f3f40 to your computer and use it in GitHub Desktop.
Dockerised Rails Development Environment (take 1)
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'
# Ignore bundler config.
/.bundle
# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep
# Ignore Byebug command history file.
.byebug_history
postgres-data

A Dockerised Rails Development Environment

Uses Docker Compose, Postgres, etc.

This is a modification of this article: https://docs.docker.com/compose/rails/

Set up the docker file, gemfile, etc. Don't forget to modify your your config/database.yml (see below)

Change your environment.rb file to allow the web console to be rendered for the guest os. e.g.: config.web_console.whitelisted_ips = '172.18.0.0/16'

General operation...

  1. Run docker-compose up
  2. First time, open a new tab and run docker-compose run web rake db:setup
  3. Use docker-compose run web bash to connect and do useful stuff (e.g. rails console)
  4. Use docker-compose down to gracefully shut things down. If not, you might have to docker-compose run web rm /myapp/tmp/pids/server.pid
default: &default
adapter: postgresql
encoding: unicode
host: db
username: postgres
password:
pool: 5
development:
<<: *default
database: myapp_development
test:
<<: *default
database: myapp_test
version: '3'
services:
db:
image: postgres
#persist data
volumes:
- ./postgres-data:/var/lib/postgresql/data
web:
build: .
#command: bundle exec bash
#rails s -p 3000 -b '0.0.0.0'
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
FROM ruby:2.3.3
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /myapp
WORKDIR /myapp
ADD Gemfile /myapp/Gemfile
ADD Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
ADD . /myapp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment