Docker

 Docker

An introduction to docker. We’ll discuss what docker is and what it isn’t, comparing it to solutions you might be more familiar with (virtualbox, vmware, etc). Next we’ll see how docker can ease development and deployment of applications with its concept of containers.

http://2014.phpday.it/

D07a7a143b14fc8309f9abb78d569344?s=128

Alexander

May 17, 2014
Tweet

Transcript

  1. None
  2. asm89 / @iam_asm89

  3. None
  4. None
  5. Dependencies

  6. ?

  7. ?

  8. ?

  9. None
  10. None
  11. None
  12. None
  13. Deployment

  14. None
  15. None
  16. None
  17. None
  18. None
  19. None
  20. None
  21. Linux containers Run everywhere

  22. Linux containers Run everything

  23. None
  24. What is a linux container?

  25. Lightweight VM • Own process space • Own network interface

    • Can run stuff as root • Can have its own /sbin/init “machine container”
  26. Lightweight VM • Own process space • Own network interface

    • Can run stuff as root • Can have its own /sbin/init “machine container” • Not having its own /sbin/init • Isolated processes • Share kernel with the host “application container” Chroot on steroids
  27. VM vs Container

  28. $ ps aux | wc -l 174 $ docker run

    -it ubuntu bash root@86f8213d57e0:/# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 4.0 0.0 18152 1856 ? Ss 23:05 0:00 bash root 9 0.0 0.0 15568 1148 ? R+ 23:05 0:00 ps aux
  29. Docker 101

  30. $ sudo apt-get update $ sudo apt-get install docker.io $

    sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker
  31. $ docker pull ubuntu

  32. $ docker images | grep ubuntu ubuntu 13.10 5e019ab7bf6d 3

    weeks ago 180 MB ubuntu saucy 5e019ab7bf6d 3 weeks ago 180 MB ubuntu precise 74fe38d11401 3 weeks ago 209.4 MB ubuntu 12.04 74fe38d11401 3 weeks ago 209.4 MB ubuntu 12.10 a7cf8ae4e998 3 weeks ago 171.2 MB ubuntu quantal a7cf8ae4e998 3 weeks ago 171.2 MB ubuntu 14.04 99ec81b80c55 3 weeks ago 266 MB ...
  33. $ docker run ubuntu echo “hello world” hello world

  34. Demo

  35. $ docker run -d ubuntu ping 127.0.0.1

  36. $ docker run -d ubuntu ping 127.0.0.1 $ docker ps

  37. $ docker run -d ubuntu ping 127.0.0.1 $ docker ps

    $ docker attach <container_id>
  38. $ docker run -d ubuntu ping 127.0.0.1 $ docker ps

    $ docker attach <container_id> $ docker stop/start/restart <container_id>
  39. Demo

  40. $ docker run ubuntu rm /etc/passwd

  41. $ docker run ubuntu rm /etc/passwd $ docker run ubuntu

    cat /etc/passwd root:x:0:0:root:/root:/bin/bash …
  42. $ docker run ubuntu rm /etc/passwd $ docker run ubuntu

    cat /etc/passwd root:x:0:0:root:/root:/bin/bash … $ docker ps -n=2
  43. $ docker run ubuntu rm /etc/passwd $ docker run ubuntu

    cat /etc/passwd root:x:0:0:root:/root:/bin/bash … $ docker ps -n=2 $ docker commit <container_id> borked-ubuntu
  44. $ docker run ubuntu rm /etc/passwd $ docker run ubuntu

    cat /etc/passwd root:x:0:0:root:/root:/bin/bash … $ docker ps -n=2 $ docker commit <container_id> borked-ubuntu $ docker run borked-ubuntu cat /etc/passwd cat: /etc/passwd: No such file or directory
  45. Demo

  46. Creating images

  47. Manually In container $ apt-get install php5-cli $ echo "<?php

    echo 'hello phpday!';" > /index.php On host $ docker commit <id> <name>
  48. Manually In container $ apt-get install php5-cli $ echo "<?php

    echo 'hello phpday!';" > /index.php On host $ docker commit <id> <name> FROM ubuntu RUN apt-get install -y php5-cli RUN echo "<?php echo 'hello phpday!';" > /index.php EXPOSE 8000 ENTRYPOINT ["php", "-S", ":8000"] Dockerfile
  49. Demo

  50. Registry

  51. None
  52. Docker powered mini-Heroku in around 100 lines of Bash.

  53. $ git push dokku master

  54. None
  55. PHP Ruby Nodejs Java Scala Go Perl ...

  56. $ wget -qO- <url> | sudo DOKKU_TAG=v0.2.3 bash https://raw.github.com/progrium/dokku/v0.2.3/bootstrap.sh

  57. Demo

  58. Try it!

  59. #docker @ freenode http://docker.io

  60. Happy shipping!

  61. @iam_asm89 https://joind.in/11309