O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Docker 初探,實驗室中的運貨鯨

4.837 visualizações

Publicada em

http://blog.fntsr.tw/articles/2015/05/28/docker-talks-on-ncu/

學校實驗室總會有些需求,架設各種服務,例如:Redmine、MySQL、Wiki、GitLab ...
以往我們都會一股腦將這些服務架設在同一主機,或是各開一台虛擬機器,放在裡面,
然後就一屆傳一屆,只要不要掛掉就繼續使用。

但到了某天,發現舊版有漏洞,或是新版有更好用的功能,
才又挖出更新說明,辛辛苦苦的將各種服務一一更新上線。
又或是老闆要求架新服務,但才發現因為虛擬機器開太多 IP 不夠用了,
只好再度將各個服務都塞在同一台電腦裡,失去原本一台機器一個服務的用意。

有沒有什麼辦法去改善這種窘境?
或是有沒有更快的方式能方便我們部署我們需要的服務?
我想,Docker 或許就是你想要的答案。

「Build, Ship, Run Any App, Anywhere」—— Docker 如是說。

有別於虛擬機器的沈重,輕量的虛擬化技術 Container 正夯,
本講座將帶聽眾認識 Docker —— 一個方便操作 Container 的工具,
讓你以更方便、更快速的方式,管理你實驗室上的各個服務。

Publicada em: Tecnologia
  • Seja o primeiro a comentar

Docker 初探,實驗室中的運貨鯨

  1. 1. 1
  2. 2. 2
  3. 3. 跨領域 正夯
  4. 4. 深藏 若虛
  5. 5. 死會 證明
  6. 6. NCHU EECSeC 
 
 
 
 
 
 
 
 

  7. 7. Now
  8. 8. 9
  9. 9. 11
  10. 10. 13
  11. 11. $  wget  -­‐qO-­‐  https://get.docker.com/  |  sh
  12. 12. Kitematic
  13. 13. 18
  14. 14. $  [sudo]  docker  [command]  [flags]  [arguments]
  15. 15. $ docker Commands: attach Attach to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes $  docker
  16. 16. $ docker version Client version: 1.62 Client API version: 1.18 Go version (client): go1.4.1 Git commit (client): a8a31ef OS/Arch (client): darwin/amd64 Server version: 1.6.2 Server API version: 1.18 Go version (server): go1.4.2 Git commit (server): 4749651 $  docker  version
  17. 17. $ docker info Containers: 3 Images: 65 Storage Driver: aufs Root Dir: /mnt/sda1/var/lib/docker/aufs … Execution Driver: native-0.2 Kernel Version: 4.0.3-boot2docker Operating System: Boot2Docker 1.6.2 (TCL 5.4); …… $  docker  info
  18. 18. $ docker run --help Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] Run a command in a new container …… $  docker  command  -­‐-­‐help
  19. 19. $  docker  run  image  execute  [argument,  …]
  20. 20. $ docker run ubuntu:14.04 /bin/echo 'Hello world' Hello world $  docker  run  image  execute  [argument,  …]
  21. 21. $ docker run -it ubuntu:14.04 /bin/bash root@af8bae53bdd3:/# $  docker  run  -­‐it  image  execute  [argument,  …]
  22. 22. $ docker run -d ubuntu:14.04 /bin/echo 
 -c "while true; do echo hello world; sleep 1; done" 1e5535038e285177d5214659a068137486f96ee5c2e85a4ac52dc83f2ebe4147 $  docker  run  -­‐d  image  execute  [argument,  …]
  23. 23. $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES 1e5535038e28 ubuntu:14.04 /bin/sh… 2 minutes ago Up 1 minute insane_babbage $  docker  ps
  24. 24. $ docker logs 1e5535038e28 hello world hello world hello world $  docker  logs  [container  ID/Name]
  25. 25. $ docker logs insane_babbage hello world hello world hello world $  docker  logs  [container  ID/Name]
  26. 26. $  docker  run  -­‐P|-­‐p  …
  27. 27. $ docker run -d -P nginx:latest Unable to find image 'nginx:latest' locally latest: Pulling from nginx 39bb80489af7: Pull complete …… 72d73c46937a: Pull complete Status: Downloaded newer image for nginx:latest 23e601370946fc9fbdfd6204e1bf70e88e6c18078a0c6ee8640acd2e6694b645 $  docker  run  -­‐d  -­‐P  image  execute  [argument,  …]
  28. 28. $ docker ps CONTAINER ID IMAGE COMMAND STATUS PORTS 23e601370946 nginx:latest "nginx … Up 1 minute 0.0.0.0:32768->443/tcp
 0.0.0.0:32769->80/tcp $  docker  ps
  29. 29. $ boot2socker ip 192.168.59.103 $  boot2ocker  ip
  30. 30. $ docker run -d -p 80 nginx:latest 40dd6835e35843fdc1853e92b9922f6406f874793c085e1f71cb3967e1157cf3 $  docker  run  -­‐d  -­‐p  container_port  …
  31. 31. $ docker ps CONTAINER ID IMAGE COMMAND STATUS PORTS 40dd6835e358 nginx:latest "nginx … Up 1 minute 443/tcp
 0.0.0.0:32770->80/tcp $  docker  ps
  32. 32. $ docker run -d -p 10080:80 nginx:latest 40dd6835e35843fdc1853e92b9922f6406f874793c085e1f71cb3967e1157cf3 $  docker  run  -­‐d  -­‐p  host_port:container_port  …
  33. 33. $ docker ps CONTAINER ID IMAGE COMMAND STATUS PORTS 40dd6835e358 nginx:latest "nginx … Up 1 minute 443/tcp
 0.0.0.0:10080->80/tcp $  docker  ps
  34. 34. $  docker  run  -­‐P|-­‐p  [argument,  …]
  35. 35. $ docker run -d -P nginx:latest Unable to find image 'nginx:latest' locally latest: Pulling from nginx 39bb80489af7: Pull complete …… 72d73c46937a: Pull complete Status: Downloaded newer image for nginx:latest 23e601370946fc9fbdfd6204e1bf70e88e6c18078a0c6ee8640acd2e6694b645 $  docker  run  -­‐d  -­‐P  image  execute  [argument,  …]
  36. 36. $ docker ps CONTAINER ID IMAGE COMMAND STATUS PORTS 23e601370946 nginx:latest "nginx … Up 1 minute 0.0.0.0:32768->443/tcp
 0.0.0.0:32769->80/tcp $  docker  ps
  37. 37. $ boot2socker ip 192.168.59.103 $  boot2ocker  ip
  38. 38. $ docker run -d -p 80 nginx:latest 40dd6835e35843fdc1853e92b9922f6406f874793c085e1f71cb3967e1157cf3 $  docker  run  -­‐d  -­‐p  container_port  …
  39. 39. $ docker ps CONTAINER ID IMAGE COMMAND STATUS PORTS 40dd6835e358 nginx:latest "nginx … Up 1 minute 443/tcp
 0.0.0.0:32770->80/tcp $  docker  ps
  40. 40. $ docker run -d -p 10080:80 nginx:latest 40dd6835e35843fdc1853e92b9922f6406f874793c085e1f71cb3967e1157cf3 $  docker  run  -­‐d  -­‐p  host_port:container_port  …
  41. 41. $ docker ps CONTAINER ID IMAGE COMMAND STATUS PORTS 40dd6835e358 nginx:latest "nginx … Up 1 minute 443/tcp
 0.0.0.0:10080->80/tcp $  docker  ps
  42. 42. $  docker  start|restart|stop|kill  contanter
  43. 43. $ docker stop nginx_container nginx_container $  docker  stop  [container  ID/Name]
  44. 44. $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES $  docker  ps
  45. 45. $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES 23e601370946 nginx:latest "nginx … 2 minutes ago EXITED(0) nginx_container $  docker  ps  -­‐a
  46. 46. $ docker start nginx_container nginx_container $  docker  start  [container  ID/Name]
  47. 47. $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES 23e601370946 nginx:latest "nginx … 10 minutes ago Up 1 minute nginx_container $  docker  ps
  48. 48. $ docker restart nginx_container nginx_container $  docker  restart  [container  ID/Name]
  49. 49. $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES 23e601370946 nginx:latest "nginx … 15 minutes ago Up 1 minute insane_babbage $  docker  ps
  50. 50. $ docker stop nginx_container nginx_container $ docker kill nginx_container nginx_container $  docker  kill  [container  ID/Name]
  51. 51. $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES $  docker  ps  -­‐a
  52. 52. $  docker  images|pull|rmi
  53. 53. $ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE nginx latest a785ba7493fd 16 hours ago 132.9 MB $  docker  images
  54. 54. $ docker pull mysql:latest latest: Pulling from mysql 7a3e804ed6c0: Pull complete …… ff78d9bb5f46: Already exists Status: Downloaded newer image for mysql:latest $  docker  pull  image_name:tag
  55. 55. $ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE nginx latest a785ba7493fd 16 hours ago 132.9 MB mysql latest ff78d9bb5f46 3 days ago 282.9 MB $  docker  images
  56. 56. $ docker rmi mysql:latest Untagged: mysql:latest Deleted: ff78d9bb5f46b3a619310a8e3f3e62b98ce08b476d0d5d4088f1853d604f8218 …… Deleted: 7a3e804ed6c015465a6cb957d032276dbff7ba8582153c38b83acd70ffdad0c6 $  docker  rmi  image_name:tag|image_id
  57. 57. 69
  58. 58. #  curl  -­‐L  https://github.com/docker/compose/releases/……  >  /usr/local/bin/docker-­‐compose   #  chmod  +x  /usr/local/bin/docker-­‐compose $  sudo  pip  install  -­‐U  docker-­‐compose
  59. 59. # docker-compose.yml web: build: . command: python app.py ports: - "5000:5000" volumes: - .:/code links: - redis
  60. 60. # docker-compose.yml service: ... ports: - "3000" - "8000:8000" - "49100:22" - "127.0.0.1:8001:8001"
  61. 61. # docker-compose.yml service: … volumes: - /var/lib/mysql - cache/:/tmp/cache - ~/configs:/etc/configs/:ro
  62. 62. # docker-compose.yml service: ... environment: RACK_ENV: development SESSION_SECRET: environment: - RACK_ENV=development - SESSION_SECRET
  63. 63. $ docker-compose up -d Creating swl_service_1… $ docker-compose up -d Recreating swl_service_1… $ docker-compose up -d --no-recreate $  docker-­‐compose  up  -­‐d
  64. 64. $ docker-compose stop Stopping swl_service_1... $  docker-­‐compose  stop
  65. 65. $ docker-compose start Starting swl_service_1... $  docker-­‐compose  start
  66. 66. $ docker-compose restart Restarting swl_service_1... $  docker-­‐compose  restart
  67. 67. $ docker-compose rm No stopped containers $ docker-compose stop && docker-compose rm Going to remove swl_service_1 Are you sure? [yN] y Removing swl_service_1... $  docker-­‐compose  rm
  68. 68. 80
  69. 69. 82
  70. 70. 83
  71. 71. 84

×