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

Docker 基礎介紹與實戰

Docker 基礎介紹與實戰

Bo-Yi Wu

April 22, 2016
Tweet

More Decks by Bo-Yi Wu

Other Decks in Technology

Transcript

  1. Why •  新人環境建置 (蜜月期?) •  多種環境建置及版本測試 – Node 4.x, 5.x ..

    – PHP 5.6, 5.7 .. – Wordpress, Discourse, Gogs, Gitlab …. 4  
  2. 問題是  …   •  宅宅 A: 那個誰誰,可以先停掉你的程序嗎? •  宅宅 B:

    CPU 跟 Ram 都爆了啦 …. •  宅宅 C: 編譯個 Router Code 要半小時啊 …. •  宅宅 D: 趁半夜沒人的時候再來用 (加班狂?) 6  
  3. 軟體工程師     •  做事效率低落 •  每天產能有限 •  浪費很多時間在 Build

    Code 上 •  如果 Server 壞了,是全 Team 放假嗎? •  週末或平日晚上頻加班 … 8  
  4. 解決   •  工程師不再抱怨 Build Server 慢 –  不會再找我麻煩了 (誤)

    •  前後端各自獨立作業 –  前端各自有獨立開發環境 •  要測試 Service (Wordpress, Jenkins, Gogs) –  不需要安裝任何 redis, mysql, php 等環境 13  
  5. Docker images •  docker pull ubuntu:14.04 – ubuntu: image name – 14.04:

    tag name, default is “latest” – host: registry.hub.docker.com 28  
  6. Ubuntu images apt-get update docker pull ubuntu:14.04 docker run –ti

    ubuntu:14.04 /bin/bash $ apt-get update && apt-get –y upgrade $ exit docker commit –m “test” xxxxx test/base:1.0 38  
  7. Ubuntu images apt-get update Nginx docker run –ti test/base:1.0 /bin/bash

    $ install nginx …… $ exit docker commit –m “test” xxxxx test/nginx:1.0 39  
  8. Ubuntu images apt-get update docker run –ti test/base:1.0 /bin/bash $

    install apache…… $ exit docker commit –m “test” xxxxx test/apache:1.0 Apache 40  
  9. Ubuntu images apt-get update Nginx docker run –ti test/nginx:1.0 /bin/bash

    $ install php5.3 …… docker commit –m “php” xx test/php:5.3 PHP 5.3 41  
  10. 練習 前端建立 node 4 及 node 5 環境 後端建立 php6

    及 php7 環境 驗證 images 是否有該執行檔 42
  11. Ubuntu images eth0 8000 port Host Docker bridge eth0 5467

    port Docker run –d –p 8000 hello 49  
  12. Ubuntu images eth0 8000 port Host eth0 80 port Docker

    run –d –p 80:8000 hello Docker bridge 50  
  13. Hello eth0 8000 port Host Docker bridge eth0 80 port

    Docker run –d ––name hello –p 80:8000 hello 51  
  14. Hello eth0 8000 port Host Docker bridge eth0 80 port

    Docker run –d –v /opt/test:/home/test ––name hello –p 80:8000 hello /opt/test /home/test 53  
  15. Ubuntu eth0 8000 port Host Docker bridge eth0 80 port

    Docker run –d ––link redis:redis –p 80:8000 hello 58  
  16. 啟動 Mysql,  Redis •  docker run –d ––name my-db –e

    MYSQL_ROOT_PASSWORD=1234 mysql •  docker run –d ––name my-redis redis 59  
  17. 連接 Mysql 及 Redis Docker run –ti ––link my-db:db \

    ––link my-redis:redis \ ubuntu /bin/bash 60  
  18. 建立 Wordpress •  docker run –d ––name my-db \ –e

    MYSQL_ROOT_PASSWORD=1234 \ mysql •  docker run ––name my-wp \ --link my-db:mysql -d \ -p 8080:80 wordpress 61  
  19. wordpress: image: wordpress links: - db:mysql ports: - 8080:80 db:

    image: mariadb environment: MYSQL_ROOT_PASSWORD: test 63  
  20. 事前準備   •  準備相關環境 – Node 4 – Node 5 – PHP5 – PHP6

    – PHP7 Images Dockerfile Yoyo/node:4 Yoyo/node:5 Yoyo/php:6 Yoyo/php:7 70  
  21. Docker run –rm \ –v folder1:folder2 \ --link mysql:mysql \

    --workdir=/app \ -e DEV=Testing\ yoyo:node5 \ /bin/bash –c “npm test” 72