1
Building
with Docker.io,
Vagrant and Node.js
a baby PaaS
Pedro Dias
@pedromdias
workshop
Daniel Gomes
@danielcsgomes
September 29, 2013
Slide 2
Slide 2 text
AGENDA
• What is Vagrant
• What is Docker
• Let's get our hands dirty! :)
2
Slide 3
Slide 3 text
3
ABOUT DANIEL GOMES
• Senior Software Engineer @ GuestCentric
• Father, Geek
• @danielcsgomes
Slide 4
Slide 4 text
4
ABOUT PEDRO DIAS
• Full Stack Engineer @ PTisp
• Lecturer @ Polytechnic Institute of Tomar
• Father, petrolhead and hiker
• @pedromdias
• apocas
Slide 5
Slide 5 text
5
What is
http://www.vagrantup.com/
?
Slide 6
Slide 6 text
• Manage virtual machines (such as Virtual Box, VMware, AWS)
• Define the configuration in code using a single file
• Can use Shell scripts, Puppet, Chef and other tools to
provisioning the Virtual Machines
• Written in Ruby
6
Slide 7
Slide 7 text
7
Why
Vagrant?
Slide 8
Slide 8 text
Is portable and easy to share
8
Slide 9
Slide 9 text
Reproducible and customizable
9
Slide 10
Slide 10 text
Virtualized and isolated
10
Slide 11
Slide 11 text
Allows you to work close
to your production environment
11
Slide 12
Slide 12 text
and makes your life easier
and everyone happy
12
Slide 13
Slide 13 text
Workflow of vagrant up
13
Vagrantfile
Provisioning
manifest
has provisioning
manifest?
yes
start provisioning the VM
VM is running
vagrant up
downloads the box if needed
and loads vagrant configurations
(share folders, port forwarding, etc)
and starts the VM
• Use (D)VCS (Git, SVN, Mercurial, etc.)
• Add the Vagrantfile and provisioning files (puppet, chef, shell
scripts, etc) to your repository
• Add .vagrant folder to your repository ignore file or your
global ignore file.
18
Slide 19
Slide 19 text
• Sharing your dev environment saves you time and makes your life easier
and everyone happy
• Vagrant manages the Virtual Machines using a configuration file
• Default provider is Virtual Box, but VMware and AWS are available too
• Vagrant can provision the VM using Puppet, Chef, Shell scripts or other
tools
Wrap Up
19
Slide 20
Slide 20 text
20
What is
http://www.docker.io/
?
Slide 21
Slide 21 text
WOULDN’T BE GREAT IF...
21
Slide 22
Slide 22 text
THAT’S DOCKER
22
Slide 23
Slide 23 text
VMS VS CONTAINERS
23
Slide 24
Slide 24 text
DOCKER BUILDER
24
Slide 25
Slide 25 text
DOCKERFILE INSTRUCTIONS
• FROM image:tag
• MAINTAINER name
• RUN command
• EXPOSE port
• ENTRYPOINT [‘cmd’, ‘arg’, ...]
• USER user
• ADD src dest
• CMD [‘cmd’, ‘arg’, ...]
25
Slide 26
Slide 26 text
DOCKERFILE
26
# Build the image of ubuntu 12.04 LTS
from ubuntu:precise
run apt-get -y wget
# Install node.js
run wget -O - http://nodejs.org/dist/v0.10.19/node-v0.10.19-linux-
x64.tar.gz | tar -C /usr/local/ --strip-components=1 -zxv
# Expose port 80 to the host machine
expose 80
FAMOUS RUN COMMAND
29
Usage: docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]
Run a command in a new container
-a=map[]: Attach to stdin, stdout or stderr.
-c=0: CPU shares (relative weight)
-cidfile="": Write the container ID to the file
-d=false: Detached mode: Run container in the background, print new container id
-e=[]: Set environment variables
-h="": Container host name
-i=false: Keep stdin open even if not attached
-privileged=false: Give extended privileges to this container
-m=0: Memory limit (in bytes)
-n=true: Enable networking for this container
-p=[]: Map a network port to the container
-t=false: Allocate a pseudo-tty
-u="": Username or UID
-dns=[]: Set custom dns servers for the container
-v=[]: Create a bind mount with: [host-dir]:[container-dir]:[rw|ro]. If "host-dir" is
missing, then docker creates a new volume.
-volumes-from="": Mount all volumes from the given container.
-entrypoint="": Overwrite the default entrypoint set by the image.
-w="": Working directory inside the container
-lxc-conf=[]: Add custom lxc options -lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"
CONNECTING
• Using hostname:port pair.
• 127.0.0.1:4243
• Using unix socket. (default since Remote API v1.3)
• unix:///var/run/docker.sock
35
Slide 36
Slide 36 text
NODE CLIENT
• dockerode
• https://npmjs.org/package/dockerode
• API feature 100% implemented and tested.
• Leverage streams when possible (a lot :-))
• Container and image abstraction.
36
Slide 37
Slide 37 text
LET’S BUILD SOMETHING
37
Slide 38
Slide 38 text
SPECIFICATION
• Deployment using Git repos
• Support apps from multiple languages
• Hipache based proxy
• Continuous stream
38
Slide 39
Slide 39 text
ARCHITECTURE
39
VM1
Drone
Docker
OS
VM2
Drone
Docker
OS
Balancer
CLI client
...
CLI client ...
Hipache
Slide 40
Slide 40 text
DEV ENVIROMNENT
• Set your name servers to: 192.241.191.162
• https://github.com/apocas/lxjs-dns
• Answers *.lxjs.dev to10.0.5.50 (Vagrant VM IP) the rest is forwarded to 8.8.8.8
• [app_name].lxjs.dev
• helloworldphp.lxjs.dev
• sdf67asks9.lxjs.dev
• ...
40