Eric Schaefer

Setting Up Docker From Nothing


Docker… Starting from Nothing

On OS X, you will need Three applications… VirtualBox, Boot2Docker and Compose.


Because the Docker daemon uses Linux-specific kernel features, you can’t run Docker natively in OS X. Instead, you must install the Boot2Docker application.

1. Download/install VirtualBox

2. Install Boot2docker and Compose to run Docker on OS X.

$ brew install boot2docker docker-compose

Follow the Homebrew instructions to manage launching on startup, etc.

3. Create a new Boot2Docker VM. You only need to do this once, yay!

$ boot2docker init
$ boot2docker start

4. Display the environment variables for the Docker client.

$ boot2docker shellinit
Writing /Users/mary/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/mary/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/mary/.boot2docker/certs/boot2docker-vm/key.pem
    export DOCKER_HOST=tcp://
    export DOCKER_CERT_PATH=/Users/mary/.boot2docker/certs/boot2docker-vm
    export DOCKER_TLS_VERIFY=1

5. Set the environment variables in your shell:

$ eval "$(boot2docker shellinit)"

You’ll need to run this for every terminal session that invokes the docker or docker-compose command.

Auto initiate this by adding the following line to the bottom of either your .zshrc or .bashrc file:

$ eval `boot2docker shellinit 2>/dev/null`

6. Run the hello-world container to verify your setup.

$ docker run hello-world

Example Dockerfile for a Rails project

In the root directory of your Rails project, create a file called Dockerfile. Example contents for our Wildeisen project would be:

FROM ruby:2.2.2

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
# patch the version of Node since apt-get would grab an olllld version
RUN curl -sL | bash -
RUN apt-get install -y nodejs

# for npm task runners
# grab newer version, not from apt-get
RUN curl -L | sh

ENV APP_HOME /project

COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
COPY package.json package.json
RUN bundle install
RUN npm install


# for running grunt task, which builds SVG sprites
RUN npm install -g grunt-cli


To build this Docker image, from Rails root run:

$ docker build .


Compose lets us configure our application from one yml file. Pretty sweet.

In the root directory of our Rails project, create a file called docker-compose.yml

Here’s a really basic example that works for my project:

  image: postgres

  image: redis

  build: .
   - .:/project
  command: bin/rails server --port 3000 --binding
   - db
   - redis
   - "3000:3000"

Then build the project with the above config:

$ docker-compose build

Now we can run it with our Docker container!

$ docker-compose up

You can find out which IP address to access the Rails server from by opening a new shell window and typing:

$ boot2docker ip

In my case, I can access, with the port we set in our yml file, 3000.

So voila, I can now see my Rails project in my browser at

Running npm watch/build tasks is easy too.

$ docker-compose run web npm run watch
$ docker-compose run web npm run build

or whatever task runners you have defined in your package.json file.