Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Workshop - Building a Baby PaaS with Vagrant, Docker.io and Node.js @ LXJS 2013

0fe2d959c89cf2d9de497a237c4ea99d?s=47 Daniel Gomes
September 29, 2013

Workshop - Building a Baby PaaS with Vagrant, Docker.io and Node.js @ LXJS 2013

In this workshop you will build a baby PaaS from scratch. Starting with your development environment using Vagrant and ending with some Docker.io and Node.js magic.

When you are building a project that needs development time and constant care across all stack, for example devops tools or PaaS related software, the complexity of your development environment will quickly increase.

You will learn how to use Vagrant in order to leverage this task saving you precious time. Using this new development environment you will fiddle with Docker.io using Node.js while building a step­by­step basic PaaS using containers running on top of a Vagrant Virtual Machine. With your new ninja Docker skills, you will develop all container logic and control using Docker’s Remote API, implement container abstraction, scalable workers and balancer.

0fe2d959c89cf2d9de497a237c4ea99d?s=128

Daniel Gomes

September 29, 2013
Tweet

More Decks by Daniel Gomes

Other Decks in Programming

Transcript

  1. 1 Building with Docker.io, Vagrant and Node.js a baby PaaS

    Pedro Dias @pedromdias workshop Daniel Gomes @danielcsgomes September 29, 2013
  2. AGENDA • What is Vagrant • What is Docker •

    Let's get our hands dirty! :) 2
  3. 3 ABOUT DANIEL GOMES • Senior Software Engineer @ GuestCentric

    • Father, Geek • @danielcsgomes
  4. 4 ABOUT PEDRO DIAS • Full Stack Engineer @ PTisp

    • Lecturer @ Polytechnic Institute of Tomar • Father, petrolhead and hiker • @pedromdias • apocas
  5. 5 What is http://www.vagrantup.com/ ?

  6. • 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
  7. 7 Why Vagrant?

  8. Is portable and easy to share 8

  9. Reproducible and customizable 9

  10. Virtualized and isolated 10

  11. Allows you to work close to your production environment 11

  12. and makes your life easier and everyone happy 12

  13. 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
  14. vagrant init vagrant up vagrant halt vagrant reload vagrant provision

    vagrant ssh vagrant suspend vagrant resume vagrant destroy 14 vagrant commands
  15. Providers 15

  16. 16 Shell scripts Ansible Provisioning

  17. 17 how to share your environment?

  18. • 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
  19. • 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
  20. 20 What is http://www.docker.io/ ?

  21. WOULDN’T BE GREAT IF... 21

  22. THAT’S DOCKER 22

  23. VMS VS CONTAINERS 23

  24. DOCKER BUILDER 24

  25. DOCKERFILE INSTRUCTIONS • FROM image:tag • MAINTAINER name • RUN

    command • EXPOSE port • ENTRYPOINT [‘cmd’, ‘arg’, ...] • USER user • ADD src dest • CMD [‘cmd’, ‘arg’, ...] 25
  26. 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
  27. DOCKER COMMAND LINE • http://docs.docker.io/en/latest/commandline/ • Containers • Images •

    Misc 27
  28. CONTAINERS • attach • run • start • stop •

    diff 28 • kill • rm • logs • cp • export • ps
  29. 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"
  30. IMAGES • commit • pull • push • images •

    rmi • search 30
  31. IMAGE REGISTRY • Registry != Index • Git’ish like behavior

    • pull • push • diff • search 31
  32. BEHAVIOR 32

  33. LOCAL SHARING • docker export 1aba8bfac7d5 > poc.tgz • cat

    poc.tgz | sudo docker import - poc • sudo docker run poc uptime 33
  34. REMOTE API • http://docs.docker.io/en/latest/api/docker_remote_api_v1.5/ • Containers • Images • Misc

    34
  35. 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
  36. 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
  37. LET’S BUILD SOMETHING 37

  38. SPECIFICATION • Deployment using Git repos • Support apps from

    multiple languages • Hipache based proxy • Continuous stream 38
  39. ARCHITECTURE 39 VM1 Drone Docker OS VM2 Drone Docker OS

    Balancer CLI client ... CLI client ... Hipache
  40. 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