Skip to content

Instantly share code, notes, and snippets.

@colinrubbert
Created June 18, 2017 23:47
Show Gist options
  • Save colinrubbert/f4130e7ec86c88c1e406881b35333329 to your computer and use it in GitHub Desktop.
Save colinrubbert/f4130e7ec86c88c1e406881b35333329 to your computer and use it in GitHub Desktop.
Dockerfile for Ruby on Rails development environment.
# Core image
FROM ubuntu:17.04
# Install dependencies
RUN apt-get update && apt-get install -y git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties software-properties-common libffi-dev nodejs
# Install Ruby
RUN apt-get update && apt-get install -y ruby ruby-dev ruby-bundler
RUN rm -rf /var/lib/apt/lists/*
RUN echo $(ruby -v)
# Install Rails
RUN gem update --system
RUN gem install bundler
RUN gem install rails
RUN echo $(rails -v)
# Create data drive to connect to host machine
RUN mkdir /data
# Install PostgreSQL 9.5
RUN apt-get update && apt-get install wget
RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ zesty-pgdg main' > /etc/apt/sources.list.d/pgdg.list
RUN wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
RUN apt-get update && apt-get install -y postgresql-common postgresql-9.5 libpq-dev
# /------- Test to make Postgres db persistent (not functioning properly) -------\
# Move postgres db to /data drive
# RUN mkdir /data/db
# RUN rsync -av /var/lib/postgresql /data/db
# RUN mv /var/lib/postgresql/9.5/main /var/lib/postgresql/9.5/main.bak
# Update postgres config file to point to the new database location
# RUN mv /etc/postgresql/9.5/main/postgresql.conf /etc/postgresql/9.5/main/postgresql.conf.bak
# RUN wget --quiet -P /etc/postgresql/9.5/main/ https://goo.gl/Dbzqg3
# RUN mv /etc/postgresql/9.5/main/Dbzqg3 /etc/postgresql/9.5/main/postgresql.conf
# RUN ls /etc/postgresql/9.5/main
# /------- End Test to make Postgres db persistent -------\
# Switch to postgres user and set postges user password
USER postgres
RUN /etc/init.d/postgresql start \
&& psql --command "ALTER USER postgres WITH SUPERUSER PASSWORD 'password';"
RUN echo $(/etc/init.d/postgresql status)
# Switch back to root user
USER root
# Add VOLUMEs to allow backup of config, logs, databases and Ruby gems
VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql", "/usr/local/bundle", "/data/db" ]
EXPOSE 3000
# /--------------------------------------------------------/
# This is just procedure and has no bearing on how the image is built, this can be deleted. These are process notes.
# Build process
# docker build -t [name_your_image] .
# Run this command at run (this runs your image and exposes port 3000):
# docker run -it -p 3000:3000 -v c:/Users:/data [name_of_your_image] bash
# Start postgres
# service postgresql start
# Move to your mounted shared drive /data
# cd data
# Move to your project folder
# cd [windows_username]/Desktop/project (<- example location)
# Create new rails project
# rails new [rails_project_name] --database=postgresql
# Move into rails directory
# cd [rails_project_name]
# Open your rails database.yml file on host machine and edit database file
# Add these entries
# -> username: postgres
# -> password: [postgres_password]
# -> host: localhost
# Create your database
# rake db:create
# Run your rails application
# rails s -b 0.0.0.0
# On host machine visit localhost:3000 and your rails app should be running since we exposed this port to your host machine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment