Bye heroku

Hello Docker

Heroku

  • Simple
  • Easy
  • Many extensions
  • Quite expensive
  • Has constraints
  • Extensions are dependecies
  • SSL is 20$/mo

Docker

  • Uses LXC, runC, AuFS 
  • Encapsulated containers

Docker Compose

  • Handles multiple containers management
  • Gives a build system
  • Hot swapping built containers

Docker Machine

  • Docker is based on Linux kernel
  • Requires Virtualbox on Mac/Windows
  • Wizard installer

Dockerfile

  • Contains the build instructions of a container
  • Well documented
  • Placed in project's root (like Gemfile, Vagrantfile etc)
FROM ruby:2.2.2

Dockerfile

FROM ruby:2.2.2

# deps
RUN apt-get update -qq && apt-get install -y build-essential nodejs npm nodejs-legacy mysql-client vim

Dockerfile

FROM ruby:2.2.2

# deps
RUN apt-get update -qq && apt-get install -y build-essential nodejs npm nodejs-legacy mysql-client vim

RUN mkdir /lunchiatto

Dockerfile

FROM ruby:2.2.2

# deps
RUN apt-get update -qq && apt-get install -y build-essential nodejs npm nodejs-legacy mysql-client vim

RUN mkdir /lunchiatto

WORKDIR /tmp
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN bundle install --without development test

Dockerfile

FROM ruby:2.2.2

# deps
RUN apt-get update -qq && apt-get install -y build-essential nodejs npm nodejs-legacy mysql-client vim

RUN mkdir /lunchiatto

WORKDIR /tmp
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN bundle install --without development test

ADD . /lunchiatto

Dockerfile

FROM ruby:2.2.2

# deps
RUN apt-get update -qq && apt-get install -y build-essential nodejs npm nodejs-legacy mysql-client vim

RUN mkdir /lunchiatto

WORKDIR /tmp
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN bundle install --without development test

ADD . /lunchiatto
WORKDIR /lunchiatto
RUN npm install -g bower
RUN bower install --allow-root

Dockerfile

FROM ruby:2.2.2

# deps
RUN apt-get update -qq && apt-get install -y build-essential nodejs npm nodejs-legacy mysql-client vim

RUN mkdir /lunchiatto

WORKDIR /tmp
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN bundle install --without development test

ADD . /lunchiatto
WORKDIR /lunchiatto
RUN npm install -g bower
RUN bower install --allow-root
RUN bundle exec rake assets:clobber
RUN bundle exec rake assets:precompile --trace

Dockerfile

docker-compose.yml

  • Maintains multiple container environment
  • Placed in project's root (like Gemfile, Vagrantfile etc)
  • docker-compose ships with docker by default
db:
  image: postgres:9.4.1
  ports:
    - "5432:5432"

docker-compose.yml

db:
  image: postgres:9.4.1
  ports:
    - "5432:5432"
web:
  build: .

docker-compose.yml

db:
  image: postgres:9.4.1
  ports:
    - "5432:5432"
web:
  build: .
  command: bundle exec puma -C config/puma.rb

docker-compose.yml

db:
  image: postgres:9.4.1
  ports:
    - "5432:5432"
web:
  build: .
  command: bundle exec puma -C config/puma.rb
  ports:
    - "3000:3000"
  links:
    - db
  env_file: .prod-env

docker-compose.yml

LANG=en_US.UTF-8
NEW_RELIC_APP_NAME=
NEW_RELIC_LICENSE_KEY=
NEW_RELIC_LOG=
RACK_ENV=production
RAILS_ENV=production
AIRBRAKE_API_KEY=
SECRET_KEY_BASE=
SENDGRID_PASSWORD=
SENDGRID_USERNAME=

.prod-env

workers Integer(ENV['WEB_CONCURRENCY'] || 3)
threads_count = Integer(ENV['MAX_THREADS'] || 1)
threads threads_count, threads_count

preload_app!

rackup      DefaultRackup
port        ENV['PORT']     || 3000
environment ENV['RACK_ENV'] || 'development'

on_worker_boot do
  ActiveRecord::Base.establish_connection
end

config/puma.rb

Starting it all up

Bye Heroku Hello Docker

By Bartek Kruszczyński

Bye Heroku Hello Docker

  • 1,218