Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

Ruoshi Ling
October 09, 2015

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

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

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

Ruoshi Ling

October 09, 2015
Tweet

More Decks by Ruoshi Ling

Other Decks in Technology

Transcript

  1. Foundation 15 Linux Kernel Linux Distribution FS Your Environments Base

    Image FS Images Container 䁆ᤈ絑ह Process Process
  2. Image 17 Linux Kernel Base Image Image Layer A Image

    Layer B Image Layer ከ Image Layer C Image Layer Ԛ Image Layer Ӱ
  3. Container Volumes Host /var/www/html …… …… Volume /var/www/html …… Container

    B Volume
 From 3f8566045a0994e..... Container A (3f8566045a....) WBSMJCEPDLFSWPMVNFT
  4. Container Volumes Custom Directory Host /var/www/html …… …… Container A

    Volume 蕰僽$POUBJOFS酭꬗䭸㹁涸鑪须俲㣰䊺竤㶸㖈 ⵱剚鄄)PTU涸须俲㣰窍銼覈
  5. %PDLFSMF FROM php:7-apache
 MAINTAINER<Ruoshi Ling <[email protected]>
 
 RUN apt-get update


    
 ADD ./script.php /app/
 
 ENTRYPOINT php
 CMD ["app/script.php"] 41
  6. Skills (1)  ⵄ欽䧴=䪾㢵⦐36/䧴Ⱖ➮䭸⟂鸮㖈♧饱 42 RUN apt-get update \
 &&

    apt-get install -y \
 wget \ 
 curl \
 php5 \
 && echo "Installed basic packages"
  7. Skills (2)  ⵄ欽&/7鏤縨갸鏤涸橇㞯隶侸 43 ENV APP_VERSION=1.2.3 \
 DB_USER="foo" \


    DB_PASSWORD="bar" \
 DB_DATABASE="app" \
 DB_HOST="127.0.0.1" \
 ENV=production
  8. $SFBUF-PDBM.BDIJOF 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
  9. $IBOHFEPDLFSDMJFOUFOWJSPONFOU 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)"
  10. $IFDLJTTFSWFSDPOOFDUJOH 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
  11. $PNQPTF$PNNBOE 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
  12. 60 # docker-compose.yml web: build: ./ links: - mysql ports:

    - "9527:80" mysql: image: mysql:5.7 environment: - MYSQL_ROOT_PASSWORD=password - MYSQL_DATABASE=wordpress .VMUJ$POUBJOFST
  13. Skills (1)  ⵄ欽FOWJSPONFOU鏤縨橇㞯隶侸《➿%PDLFSMF涸 갸鏤⧩ 62 # docker-compose.yml web: ....

    environment: - DB_USER=elephant
 - DB_PASSWORD=ilovePHPfOEvEr
 - DB_DATABASE=elephant
  14. 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
  15. 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"