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.

當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

2,381 views

Published on

距離去年講述「運用 Docker 部署 PHP 專案」已經過了一年,Docker 生態系逐漸成長,Machine、Compose、Swarm 皆趨於穩定、值得投入。本議程將承襲去年議程的概念,並講述如何透過這些工具利用 Docker 協助我們更方便的開發、測試、部署、遷移我們的 PHP 專案。

Ps. 本議程謹會概略提到 Docker 概念作為複習,不會針對指令一一教學、建議會眾在議程前,能先了解 Docker 基本使用方式。

Published in: Technology
  • Be the first to comment

當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)

  1. 1. 1 PHPConf Taiwan 2015
  2. 2. 2 2015-11-01-a p45 VALUME -> VOLUME @date
  3. 3. 3
  4. 4. 4
  5. 5. 5
  6. 6. 6
  7. 7. 7 machine compose
  8. 8. 8
  9. 9. 9
  10. 10. 10 鯨⿂搬運的貨櫃 在你還在打包的時候 貨櫃早就部署好了 你有想過這個嗎? 沒有 因為你只會想到你⾃⼰。
  11. 11. Foundation 11 Host OS Hypervisor Guest OS …
  12. 12. Foundation 12 Linux Kernel Linux Distribution FS …
  13. 13. Foundation 13 Linux Kernel Linux Distribution FS … Base Image FS ….
  14. 14. Foundation 14 Linux Kernel Your Environments Container Linux Distribution FS Base Image FS ….
  15. 15. Foundation 15 Linux Kernel Linux Distribution FS Your Environments Base Image FS Images Container Process Process
  16. 16. Image 16 Linux Kernel Base Image Image Layer A Image Layer B
  17. 17. Image 17 Linux Kernel Base Image Image Layer A Image Layer B Image Layer Image Layer C Image Layer Image Layer
  18. 18. Image 18 Linux Kernel Ubuntu PHP 5.5 Apache PHP 7 Nginx Apache Nginx
  19. 19. Image 19 Linux Kernel Ubuntu PHP 5.5 Apache PHP 7 Nginx Apache Nginx CentOS
  20. 20. Container 20 Images Container
  21. 21. Container Container 21 Images Process Executing Running
  22. 22. Container Container 22 Images Exited (Stop)
  23. 23. Container 23 Images Changed FS Process Executing Host FS Running
  24. 24. Container Container 24 Images Changed FS Host FS Exited (Stop)
  25. 25. Container A Container Links 25 Container B Container C
  26. 26. App Container Links 26 SQL DB Redis
  27. 27. Links Contributes 27
  28. 28. Container Volumes 3f8566045a0994e..... Host /var/www/html …… …… Container A (3f8566045a....) Volume
  29. 29. Container Volumes Host /var/www/html …… …… Volume /var/www/html …… Container B Volume
 From 3f8566045a0994e..... Container A (3f8566045a....)
  30. 30. Container Volumes Host …… 3f8566045a0994e.....
  31. 31. Container Volumes Custom Directory Host /var/www/html …… …… Container A Volume
  32. 32. Volume Contributes 32
  33. 33. 33
  34. 34. 34
  35. 35. 35
  36. 36. 36
  37. 37. 37
  38. 38. 38
  39. 39. 40
  40. 40. FROM php:7-apache
 MAINTAINER<Ruoshi Ling <foo@bar.tw>
 
 RUN apt-get update
 
 ADD ./script.php /app/
 
 ENTRYPOINT php
 CMD ["app/script.php"] 41
  41. 41. Skills (1) 42 RUN apt-get update 
 && apt-get install -y 
 wget 
 curl 
 php5 
 && echo "Installed basic packages"
  42. 42. Skills (2) 43 ENV APP_VERSION=1.2.3 
 DB_USER="foo" 
 DB_PASSWORD="bar" 
 DB_DATABASE="app" 
 DB_HOST="127.0.0.1" 
 ENV=production
  43. 43. Skills (3) 44 ENV SETUP_DIR="/var/cache/app"
 
 COPY assets/setup/ ${SETUP_DIR}/
 
 RUN bash ${SETUP_DIR}/install.sh
  44. 44. Skills (4) 45 COPY entrypoint.sh /sbin/entrypoint.sh
 RUN chmod 755 /sbin/entrypoint.sh
 
 ENTRYPOINT ["/sbin/entrypoint.sh"]
 CMD ["app:start"]
  45. 45. Skills (5) 46 #!/bin/bash
 ln -sf /data/db /var/lib/mysql
 ln -sf /data/uploads /app/uploads ......
 VOLUME ["/data"]
 ENTRYPOINT ["/sbin/entrypoint.sh"]
  46. 46. Contributes 47
  47. 47. 48 compose swarm machine
  48. 48. 49 docker machine
  49. 49. 50 $ docker-machine create --driver virtualbox default Creating VirtualBox VM... Creating SSH key... Starting VirtualBox VM... Starting VM... To see how to connect Docker to this machine, run: docker-machine env default
  50. 50. 51 $ docker-machine env default
 export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.99.100:2376" export DOCKER_CERT_PATH="/Users/fntsr/.docker/ machine/machines/default" export DOCKER_MACHINE_NAME="default" # Run this command to configure your shell: # eval "$(docker-machine env default)" $ eval "$(docker-machine env default)"
  51. 51. 52 $ docker version Client: Version: 1.8.2 .... Server: Version: 1.8.2 API version: 1.20 Go version: go1.4.2 Git commit: 0a8c2e3 Built: Thu Sep 10 19:10:10 UTC 2015 OS/Arch: linux/amd64
  52. 52. 53 $ docker-machine create --driver .... Generic Create machines using an existing VM/Host with SSH.
  53. 53. 54
  54. 54. 55 docker compose
  55. 55. 56 自從會用 Docker Compose 後,我 就不再下指令了呢。 認同請分享 身體健康、萬事如意、南無阿彌陀佛 有緣認識你真好
  56. 56. 57 # Comment <service_name>: attribute: <value> attribute: - item1 - item2
  57. 57. 58 # docker-compose.yml web: image: php:7-fpm ports: - "5566:80" volumes: - .:/app
  58. 58. 59 # create container(s) $ docker-compose up -d # start container(s) $ docker-compose start # stop container(s) $ docker-compose stop # remove container(s) $ docker-compose rm
  59. 59. 60 # docker-compose.yml web: build: ./ links: - mysql ports: - "9527:80" mysql: image: mysql:5.7 environment: - MYSQL_ROOT_PASSWORD=password - MYSQL_DATABASE=wordpress
  60. 60. 61 # development.yml web: extends: file: docker-compose.yml service: web environment: - ENV=development - DB=sqlite3
  61. 61. Skills (1) 62 # docker-compose.yml web: .... environment: - DB_USER=elephant
 - DB_PASSWORD=ilovePHPfOEvEr
 - DB_DATABASE=elephant
  62. 62. Skills (2) 63 # docker-compose.yml web: volumes: - ./app:/app db: volumes: - ./db:/var/lib/mysql
  63. 63. Skills (3) 64 # docker-compose.yml web: extends: file: common.yml service: web environment: - ENV=testing - DB=mysqli db: ......
  64. 64. Skills (4) 65 # docker-compose.yml web: .... restart: always
  65. 65. `docker run` 66
  66. 66. 67
  67. 67. 68
  68. 68. 69 web: image: wordpress links: - db environment: - WORDPRESS_DB_PASSWORD=password ports: - "9527:80" db: image: mysql:5.7 environment: - MYSQL_ROOT_PASSWORD=password - MYSQL_DATABASE=wordpress
  69. 69. 70
  70. 70. 71 php5: extends: file: app.yml service: web image: php:5-fpm ports: - "11024:80" php7: extends: file: app.yml service: web image: php:7-fpm ports: - "11025:80"
  71. 71. 72
  72. 72. 73

×