Introduction to docker

3,221 views

Published on

Published in: Technology

Introduction to docker

  1. 1. Introduce to
  2. 2. Outline What is docker? Why docker? Dockerfile
  3. 3. What is docker? An open platform for developing, shipping, and running applications
  4. 4. What it want to solve?
  5. 5. The matrix from hell “You've got all types of servers, all types of different languages and frameworks, and all types of application versions to try and maintain across those platforms”
 - Ben Golub, CEO of Docker
  6. 6. The matrix from hell
  7. 7. We need a container
  8. 8. The matrix from hell
  9. 9. The matrix from hell
  10. 10. Installation
  11. 11. From ubuntu mainstream Docker goes into Ubuntu mainstream since 14.04 Currently, v0.9 apt-get install docker.io
  12. 12. From Official Repo The latest version: v1.0 echo deb https://get.docker.io/ubuntu docker main > / etc/apt/sources.list.d/docker.list apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9 apt-get update apt-get install lxc-docker
  13. 13. Why Docker?
  14. 14. Fast and less overhead Image versioning Portable
  15. 15. Fast and less overhead
  16. 16. VM v.s. Docker
  17. 17. VM v.s. Docker Server Host OS
  18. 18. VM v.s. Docker Server Host OS Hypervisor
  19. 19. VM v.s. Docker Server Host OS VM VM Hypervisor
  20. 20. VM v.s. Docker Server Host OS VM VM Guest OS Hypervisor
  21. 21. VM v.s. Docker Server Host OS VM VM Guest OS Hypervisor Dep.
  22. 22. VM v.s. Docker Server Host OS VM VM Guest OS Hypervisor Dep. App
  23. 23. VM v.s. Docker Server Host OS VM VM Guest OS Hypervisor Dep. App Server Host OS
  24. 24. VM v.s. Docker Server Host OS VM VM Guest OS Hypervisor Dep. App Server Host OS Docker Engine
  25. 25. VM v.s. Docker Server Host OS VM VM Guest OS Hypervisor Dep. App Server Host OS Container Container Docker Engine
  26. 26. VM v.s. Docker Server Host OS VM VM Guest OS Hypervisor Dep. App Server Host OS Container Container Docker Engine Image1
  27. 27. VM v.s. Docker Server Host OS VM VM Guest OS Hypervisor Dep. App Server Host OS Container Container Docker Engine Image1 Image2
  28. 28. VM v.s. Docker Server Host OS VM VM Guest OS Hypervisor Dep. App Server Host OS Container Container Docker Engine Image1 App1 Image2
  29. 29. VM v.s. Docker Server Host OS VM VM Guest OS Hypervisor Dep. App Server Host OS Container Container Docker Engine Image1 App1 Image2 App2
  30. 30. VM v.s. Docker Server Host OS VM VM Guest OS Hypervisor Dep. App Server Host OS Container Container Docker Engine Image1 App1 Image2 App2 App3
  31. 31. Live Demo IP: 10.10.100.108 Username: test Password: 123456
  32. 32. docker pull Download image from Docker Hub docker pull [image] Ex: docker pull debian
  33. 33. docker run (1) docker run [image] [command] -i interactive mode -t pseudo-tty Ex: docker -i -t run debian /bin/bash
  34. 34. Image versioning
  35. 35. Image v.s. Container Base on LXC and AUFS Images are read-only Read / write on container Files in container won’t keep 
 unless you commit
  36. 36. Image v.s. Container Base on LXC and AUFS Images are read-only Read and write on container Files in container won’t keep 
 unless you commit
  37. 37. Image v.s. Container docker pull debian
  38. 38. Image v.s. Container docker pull debian docker run debian /bin/bash
  39. 39. docker commit docker commit [Container ID] [image name] docker commit 1c1f5 new_image
  40. 40. Image v.s. Container docker pull debian docker run debian /bin/bash
  41. 41. Image v.s. Container docker pull debian docker commit docker commit docker run debian /bin/bash
  42. 42. Image v.s. Container docker pull debian docker commit docker commit docker run debian /bin/bash
  43. 43. Portable Runs on all major Linux distributions Boot2docker for Mac and Windows users A ~25 MB tiny VM inside
  44. 44. Ship your container There are three ways to ship your container: Docker Hub (docker push) docker save docker export
  45. 45. docker save / load This packing will preserve the history of a docker docker save [Image Name] > [Archive Name] docker load < [Archive Name]
  46. 46. docker export / import This way only keep the difference docker export [Container ID] > [Archive Name] cat [Archive Name] | docker import - [Image Name[:Tag]]
  47. 47. Separation of Data and App
  48. 48. docker run (2) -v [host directory]:[container directory]
 Bind mount a volume -p [host port]:[container port]
 Publish a container's port to the host
  49. 49. Other useful command docker ps docker images docker kill docker rm docker rmi docker logs docker inspect
  50. 50. Dockerfile
  51. 51. Syntax FROM RUN ENV ADD VOLUME EXPOSE CMD
  52. 52. Example
  53. 53. docker build docker build -t [Image Name[:Tag]]
 <path to Dockerfile> docker build -t my_image:v1 .
  54. 54. Build once, run anywhere
  55. 55. Examples
  56. 56. My Concern Easy to setup over a VM Separate data and application Reproduce my environment fast
  57. 57. Jenkins Initialize shared volume before service start Use supervisor to manage multiple services
  58. 58. One-time script
  59. 59. Can not use upstart
  60. 60. Use supervisor
  61. 61. Summarize
  62. 62. Do one thing at a time Treat a docker container as an app
  63. 63. Ecosystem CoreOS - Work with SystemD Openstack - An instance type Docker Hub (Docker Index) Many providers
 - Digital Ocean, EC2, Linode, Google Cloud Platform
  64. 64. Gotcha Don’t have its /sbin/init (Issue 1024) Share kernel, can not run different Linux Kernel at a time Use --privileged if needed
  65. 65. Not mentioned Link to another container Use share volume on another container
  66. 66. Q & A

×