Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Docker容器微服務 x WorkShop

559 views

Published on

迎棧 Open Ecosystem Workshop
https://www.accupass.com/event/1903040308021001847652?fbclid=IwAR0pl3ZHVXsN9Qk3fM0SxTS7IhNjdiEsOsQOsuRC8xRzH5Qxi1NKYD9xFAE

Published in: Technology
  • Be the first to comment

Docker容器微服務 x WorkShop

  1. 1. 容器微服務實作 Philipz (鄭淳尹) 3/21 Open Ecosystem Workshop https://goo.gl/q4RF8p
  2. 2. Docker 相關經歷 Docker.Taipei 共同發起人 2014 COSCUP/iThome Summit 講者 2015 Microsoft Azure 開發者大會 講者 2016 COSCUP Docker 進階工作坊 2016 元智大學資工系 Docker 專題演講 2016 義守大學資工系 Docker 研習營 2017 逢甲大學資工系 Docker 研習班
  3. 3. 課程大綱 1. Docker 簡介及生態系工具 2. Docker 基本操作 3. Docker Network 與微服務實作 4. Docker Compose 快速部署微服務 5. Compose 部署到 Kubernetes 6. 結語
  4. 4. 1. Docker 簡介
  5. 5. 虛擬化技術的歷史 ● IBM zOS ● 虛擬化軟體 - VMware, KVM, Xen, VirtualBox ● Hardware-assisted virtualization 硬體加速 ● Paravirtualization 半虛擬化 ● 作業系統層虛擬化 a. OpenVZ b. LXC c. Docker ● IaaS, PaaS, SaaS - Snapshot, Migration
  6. 6. 容器與虛擬化架構差異 Instance實例
  7. 7. 容器與虛擬機技術特性比較 特性 容器 虛擬機 啟動速度 秒級 分鐘級 性能 接近原生 較差 記憶體使用 很少 較多 硬碟使用 一般為MB 一般為GB 運行數量 單機支援上千個容 器 通常為幾十個VMs 隔離性 安全隔離 完全隔離 遷移性 優異 一般 勝 勝 勝 勝 勝 勝 勝
  8. 8. Containers vs. VMs 虛擬化架構 容器化架構 容器+虛擬化架構
  9. 9. The Matrix of Hell
  10. 10. 1.1 Docker 生態系相關工具
  11. 11. Docker是什麼? 作業系統層虛擬化 (Operating system–level virtualization) v0.9 Libcontainer → runC Windows Container
  12. 12. Docker Engine Docker Host 靜態到執行時期
  13. 13. Docker Tools
  14. 14. Docker Compose ● 一鍵完成多個容器 ● docker-compose.yml ● 支援 Docker Network ● 支援 Docker Volume ● 建構完整軟體服務 ○ 如:3-tier ● 快速建置測試模擬環境
  15. 15. Docker Machine ● 在多種平台上建立 VM ● 一套工具適用所有雲端平台 、虛擬化平台 ● 內建 Docker Engine ● 具備 SSH 功能 ● 輕易切換多個平台 ○ Docker API ● 只支援 Linux-based VM
  16. 16. Docker Swarm ● Docker Engine 內建功能 ● 容器叢集系統 ○ K8S、Mesos ● 大型容器運算平台 ● 內建分散式鍵值儲存功能 ● Manager-Node架構 ○ Overlay、Compose YML ● DNS-based 服務發現機制
  17. 17. Docker Registry ● Docker 映像檔儲存服務 ● 私有 Docker Hub ● 雲端平台提供代管服務 ○ Azure、AWS、GCP ● Tag 版本控管 ● 需第三方 OAuth 認證,Harbor ● 建議直接使用雲端代管服務
  18. 18. Docker EE & UCP
  19. 19. Docker 容器架構
  20. 20. 容器使用方式 Commit Push Pull Deploy
  21. 21. 2. Docker基本操作 https://labs.play-with-docker.com/
  22. 22. Install Docker Install Docker on Ubuntu or curl -sSL https://get.docker.com/ | sh and docker run hello-world sudo usermod -aG docker $USER
  23. 23. Docker Desktop for Windows ● Windows 10 Professional or Enterprise only ● WSL(Windows Subsystem for Linux)
  24. 24. Docker Desktop for Windows ● Windows 10 Professional or Enterprise only ● WSL(Windows Subsystem for Linux)
  25. 25. Docker 管理用指令
  26. 26. Docker 映像檔指令 - docker image
  27. 27. Ctrl-p Ctrl-q Docker容器指令(1) - docker container
  28. 28. Docker容器指令(2) - docker container
  29. 29. 3. Docker Network 指令
  30. 30. TCP/IP Foundation www.google.com, www 是 hostname, google.com 是 domain name. Localhost: 127.0.0.1 TCP/UDP Port: 0-65535 = 2^16, but 0 是保留不可使用的連接埠 Private IP: 10.0.0.0/8 172.16.0.0/12 ~ 172.31.0.0/12 192.168.0.0/16
  31. 31. Network 相關指令 https://docs.docker.com/engine/userguide/networking/
  32. 32. Docker 內建 Network Drivers ● Bridge ● Overlay ● MACVLAN ● Host ● None 不要再使用 “link”, 改用 network. Docker Reference Architecture: Designing Scalable, Portable Docker Container Networks Docker Plug-In Network Drivers ● weave ● calico Docker Plug-In IPAM Drivers ● infoblox
  33. 33. 3. Docker Network 微服務實作
  34. 34. 練習一 $ docker network ls $ ifconfig $ docker run -ti --rm busybox sh cat /etc/hosts, ifconfig $ docker network inspect bridge $ docker run -itd --name=container1 busybox $ docker run -itd --name=container2 busybox $ docker exec -ti container2 sh ping -w3 172.17.0.2, ping container1
  35. 35. 練習二 $ docker network create vlan_1 $ docker network inspect vlan_1 $ ifconfig | more $ docker run --network=vlan_1 -itd --name=container3 busybox $ docker network inspect vlan_1 $ docker run --network=vlan_1 -itd --name=container4 busybox $ docker exec -ti container4 sh ping -w3 172.17.0.2, ping container1, ping container3
  36. 36. 練習三 $ docker network create wp_db $ docker pull mysql:5.7 $ docker pull wordpress $ docker run -d --name db --network=wp_db -e MYSQL_ROOT_PASSWORD=wordpress -e MYSQL_DATABASE=wordpress -e MYSQL_USER=wordpress -e MYSQL_PASSWORD=wordpress mysql:5.7 $ docker run -d --name wp -p 80:80 --network=wp_db -e WORDPRESS_DB_HOST=db:3306 -e WORDPRESS_DB_PASSWORD=wordpress wordpress
  37. 37. 4.1 Docker Compose 基本指令
  38. 38. 安裝 Docker Compose sudo curl -L "https://github.com/docker/compose/releases/download/1.1 4.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose 然後 sudo chmod +x /usr/local/bin/docker-compose docker-compose -v
  39. 39. Docker Compose 指令 (1/2) Commands: build Build or rebuild services bundle Generate a Docker bundle from the Compose file config Validate and view the compose file create Create services down Stop and remove containers, networks, images, and volumes events Receive real time events from containers exec Execute a command in a running container help Get help on a command kill Kill containers logs View output from containers pause Pause services port Print the public port for a port binding
  40. 40. Docker Compose 指令 (2/2) Commands: ps List containers pull Pull service images push Push service images restart Restart services rm Remove stopped containers run Run a one-off command scale Set number of containers for a service start Start services stop Stop services unpause Unpause services up Create and start containers version Show the Docker-Compose version information
  41. 41. Compose 檔案說明 一次執行多個容器,建構完整服務 必須是 docker-compose.yml 相同目錄:docker-compose up -d Docker 會自動建置包含 Dockerfile 的子目錄 支援 Docker Network, Volume 1.13 版本支援 Swarm mode. Quickstart: Compose and WordPress
  42. 42. 4.2 Docker Compose 快速部署微服務
  43. 43. Compose File Sample (1/2) version: '2' services: db: image: mysql:5.7 volumes: - db_data:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: wordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress
  44. 44. Compose File Sample (1/2) wordpress: depends_on: - db image: wordpress:latest ports: - "80:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_PASSWORD: wordpress volumes: db_data:
  45. 45. Compose & Wordpress ● 水平擴展 wordpress:scale nslookup wordpress docker-compose restart webproxy
  46. 46. Microservices Java Worker Docker Birthday #3 training
  47. 47. Microservices .NET Worker Docker Birthday #3 training
  48. 48. 5. Compose 部署到 Kubernetes
  49. 49. Compose on Kubernetes ● Offical solution, 2018-12-04, dockerconf 2018
  50. 50. Play with Kubernetes https://labs.play-with-k8s.com/
  51. 51. Steps of Deploy to K8S 1. git clone 2. Setup up Kubernetes Cluster a. Run bootstrap-pwk.sh b. kubeadm join c. kubectl get nodes 3. Run prepare-pwk.sh 4. kubectl get stack 5. kubectl get svc
  52. 52. Compose to Azure AKS
  53. 53. 6. 結語
  54. 54. Open SourceOpen HardwareOpen Architecture
  55. 55. Container Principle 貨櫃交付原則 ● One Container ● One Customer ● One Commodity 軟體貨櫃 ● One Container ● One Process 我是航運大王麥 克連,不是終極 警探的麥克連!
  56. 56. Microservices(微服務)
  57. 57. 作業系統容器 vs. 應用程式容器
  58. 58. 容器式系統架構
  59. 59. Cloud Native Architecture http://www.infoq.com/cn/articles/microservices-post-kubernetes
  60. 60. 6.1 相關線上學習資源
  61. 61. Docker 線上自學網站 Docker 從入門到實踐 https://yeasy.gitbooks.io/docker_practic e/content/ https://www.katacoda.com/ https://training.play-with-docker.com/
  62. 62. Docker 線上自學網站 Docker 從入門到實踐 gitbook.com/book/philipzheng/docker_p ractice/
  63. 63. Docker 線上自學網站 Docker 從入門到實踐 gitbook.com/book/philipzheng/docker_p ractice/
  64. 64. 延伸閱讀
  65. 65. Thank you Docker可省下比金錢更寶貴的時間!

×