Skip to content
Example Rails 4.2 application with a Vagrant + Docker based development environment
Ruby Shell CSS JavaScript CoffeeScript
Branch: master
Clone or download
Pull request Compare This branch is 5 commits ahead, 6 commits behind TalkingQuickly:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app
bin
config
db
docker
lib
log
public
test
.env
.gitignore
Dockerfile
Gemfile
Gemfile.lock
README.md
Rakefile
Vagrantfile
config.ru
d

README.md

Rails development using docker

Local setup

  • Requirements

  • Download host OS image for docker host OS.

% vagrant box add precise64 http://files.vagrantup.com/precise64.box
  • Build Docker images and run containers.
    • This would take 30 minutes.
    • Password of your host OS is required to mount current directory by NFS.
% vagrant up

Usage

  • d command is utility for rails development.
Usage : ./d command
Commands:
rc - Rails Console
rdbm - Migrate Database
restore-db - Restoring drop db, migrate and put seed
restart - Restart rails app after bundling gems
rebuild - Rebuild the docker container with latest Gemfile and restart
cmd "bundle exec something" - Run the command in quotes in /app
  • To execute rspec
% ./d cmd bundle exec rspec
  • To execute bundle install
% ./d restart
  • To stop host machine, shutdown the Docker host OS on Virtualbox.
% vagrant halt
  • Just want to get a rails server instance.
$ docker run -it -v /app:/app --link redis:redis --link mysql:db rails:latest /bin/bash
  • To acquire console of rails server
    • To exit the console, Ctrl + Z or Ctrl + C
$ docker attach --sig-proxy=false rails

Rebuild

  • Rebuild from VirtualBox VM
  • This takes 30 minutes.
% vagrant destroy && vagrant up
  • Rebuild docker images by referring Dockerfile.
    • This uses docker image cache.
    • bundle install will be ran.
    • This takes 5 minutes.
% vagrant provision

Issues

  • MySQL's permission for docker allows connection from anywhere.
    • I'd like to restrict MySQL incoming connection from rails server and host computer.

Expressions

  • % indicates prompt of host computer.
  • $ indicates prompt of VirtualMachine(=docker host) on vagrant.
  • # indicates prompt of Docker container.
You can’t perform that action at this time.