Nithin Bekal

Posts About Notes Slides

Docker

Docker for Rails Development

brew install docker docker-machine docker-compose
docker-machine create --driver virtualbox default
FROM ruby:2.2.0

RUN apt-get update -qq && apt-get install -y build-essential

# for postgres
RUN apt-get install -y libpq-dev

# for nokogiri
RUN apt-get install -y libxml2-dev libxslt1-dev

# for a JS runtime
RUN apt-get install -y nodejs

ENV APP_HOME /myapp
RUN mkdir $APP_HOME
WORKDIR $APP_HOME

ADD Gemfile* $APP_HOME/
RUN bundle install

ADD . $APP_HOME
version: '2'
services:
  db:
    image: postgres:9.4.1
    ports:
      - "5432:5432"

  web:
    build: .
    command: bin/rails server --port 3000 --binding 0.0.0.0
    ports:
      - "3000:3000"
    links:
      - db
    volumes:
      - .:/app

Install

To install on OSX:

brew install boot2docker
boot2docker init

Start it by:

boot2docker start

You will see this:

Waiting for VM and Docker daemon to start...
.......................ooooooooooooooooooooo
Started.
Writing /Users/nithin/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/nithin/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/nithin/.boot2docker/certs/boot2docker-vm/key.pem

To connect the Docker client to the Docker daemon, please set:
    export DOCKER_HOST=tcp://192.168.59.103:2376
    export DOCKER_CERT_PATH=/Users/nithin/.boot2docker/certs/boot2docker-vm
    export DOCKER_TLS_VERIFY=1

To have launchd start boot2docker at login:

ln -sfv /usr/local/opt/boot2docker/*.plist ~/Library/LaunchAgents

Then to load boot2docker now:

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.boot2docker.plist

Bookmarks