Slide 1

Slide 1 text

Introduction to Docker by @michaelsauter

Slide 2

Slide 2 text

How do you develop for the web? Directly on your OS? Inside a VM? There is another way ... Docker!

Slide 3

Slide 3 text

What is Docker? Based on Linux containers virtualization method for running isolated Linux systems on a host Open-source tool to make it easy and accessible

Slide 4

Slide 4 text

It's like a ... Lightweight VM Isolated process just like a VM, only smaller and faster run one process inside a container

Slide 5

Slide 5 text

What forms a Docker container?

Slide 6

Slide 6 text

Why Docker? Build once ... run anywhere isolated from host (e.g. build locally, run remotely) Isolation between containers avoid dependency hell Automation & Abstraction build, start, stop, attach, remove etc. Reusable services (via Docker Index) MySQL, PostgreSQL, Redis, ... images playgrounds for frameworks?

Slide 7

Slide 7 text

Alright, alright, here's the demo ... ... a Sinatra blog! Ruby Based on d11wtq/ruby , running bundle exec rackup Linked to ... PostgreSQL Using orchardup/postgresql , running postgres

Slide 8

Slide 8 text

PostgreSQL container # Create and start container docker run \ --env POSTGRESQL_DB=sinatra --env POSTGRESQL_USER=sinatra --env POSTGRESQL_PASS=sinatra \ --publish 5432:5432 \ --detach --name sinatra_db orchardup/postgresql

Slide 9

Slide 9 text

Sinatra container # Dockerfile (describes build steps) FROM d11wtq/ruby RUN sudo apt-get install -y -q libpq-dev WORKDIR /data CMD bundle install --path vendor && bundle exec rake db:migrate && bundle exec rackup # Build image docker build -t michaelsauter/sinatra-example . # Create and start container docker run \ --env POSTGRESQL_DB=sinatra --env POSTGRESQL_USER=sinatra --env POSTGRESQL_PASS=sinatra \ --link sinatra_db:db \ --publish 9292:9292 \ --volume /Code/web-dev-meetup/app:/data \ --detach --name sinatra_app michaelsauter/sinatra-example # In app.rb db = URI.parse(ENV["DB_PORT"]) # Set by Docker, e.g. tcp://172.17.0.2:5432 ActiveRecord::Base.establish_connection( adapter: "postgresql", host: db.host, port: db.port, username: ENV["POSTGRESQL_USER"], password: ENV["POSTGRESQL_PASS"], database: ENV["POSTGRESQL_DB"], encoding: "utf8" )

Slide 10

Slide 10 text

Demo, for real Ok, I'll cheat: I have already downloaded / built the images, and I'm using a small tool, , which will save me the typing. Crane

Slide 11

Slide 11 text

Thank you! Questions? Sinatra environment available at github.com/michaelsauter/sinatra-crane-env BTW, this presentation runs in Docker, too :) It's using a container running NodeJS to provide Markdown + speaker notes support for reveal.js