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

前端工程師一定要知道的 Docker 虛擬化容器技巧

前端工程師一定要知道的 Docker 虛擬化容器技巧

這是一份 IT 人寫給前端工程師的 Docker 入門簡報,包含了 Docker 觀念介紹、入門指令和一個小小的 e2e test demo。相信藉由一步步的等級提升,我們都可以早日成為大師,並提早下班的 (笑)。
 
* Record - https://youtu.be/k5iwKUZY9tk
* Demo video - https://youtu.be/XqCt8gk9AdI
* Demo code - https://github.com/chusiang/takaojs1607-docker-demo
 
#Docker

Chu-Siang Lai

July 04, 2016
Tweet

More Decks by Chu-Siang Lai

Other Decks in Technology

Transcript

  1. [ chusiang@takaojs ~ ] $ cat .profile # 㲺Ռᗼ /

    chusiang.lai (at) gmail.com / http://note.drx.tw
  2. 橕ෝ㲺Ռᗼ • 4 ଙ犥Ӥ IT 妿涢牐 • 匍肬 DrSays IT

    ૡ纷䒍牐 • ܎ଙ犥Ӥጱ Docker ֵአ妿涢牐 • ෝ Docker Hub 獤Ձጱ Images物 • php7 • phpmyadmin • redis.dockerfile • gitbook • vim-and-vi-mode 2
  3. 獮ᒒૡ纷䒍ฎՋ讕牫 11 • ܈獌膢ྎ萬䰬䰬᮷ᥝ䨝ጱՈ牐 JavaScript jQuery RWD Git Sublime Text

    Vim HTML5 CSS Node.js JSON Firefox Safari Chrome IE Django PHP Laravel Skitch Python UI UX
  4. ℂ 2014 ଙ樄ত牧Docker ᮷ฎ᯿ᥝ IT ଙ䨝Ӿ磧砋ಋ ጱ䣣֖ԏӞ牧膏 Docker 磪 橕ጱᄍ拻犖䁰䁰粁笕牐

    Docker ጱ蜫蝧缋蚏牧犋ݝฎࢩ 傶 Container ದ蔩๜蛪牧ๅ᯿ ᥝጱ橕棎ฎ Docker ጱڊ匍牧 ୚粁ԧ IT 礍䯤ጱ碝虋ᶐ牐 iThome - http://goo.gl/lJPQLF 16
  5. Docker 傶Ջ讕䨝穉㯽翄 VM 斕ᰁ牫ࢩ傶੝᪒ԧ N 㮆ਠ碉ጱ Guest OS牐 Server Host

    OS Hypervisor Guest OS Guest OS Bins/Libs Bins/Libs App A App B VM 1 VM 2 Server Host OS Docker Engine Bins/Libs Bins/Libs App A App B Container 1 Container 2 18
  6. Docker ฎெ讕螀֢ጱ牫 19 container container image image Docker Registry 1.ℂ

    Registry ӥ斉 image 2.ֵአ image ୌ缏
 container 5.Ӥ㯽 image ک Registry 4. 疥ୌᗝঅጱ
 container
 㱪ਂ౮ image 3. ୌᗝ Infrastructure
  7. Docker ฎெ讕螀֢ጱ牫 20 container container image image Docker Registry 1.ℂ

    Registry ӥ斉 image 2.ֵአ image ୌ缏
 container 5.Ӥ㯽 image ک Registry 4. 疥ୌᗝঅጱ
 container
 㱪ਂ౮ image 3. ୌᗝ Infrastructure
  8. Docker ฎெ讕螀֢ጱ牫 21 container container image image Docker Registry 1.ℂ

    Registry ӥ斉 image 2.ֵአ image ୌ缏
 container 5.Ӥ㯽 image ک Registry 4. 疥ୌᗝঅጱ
 container
 㱪ਂ౮ image 3. ୌᗝ Infrastructure
  9. Docker ฎெ讕螀֢ጱ牫 22 container container image image Docker Registry 1.ℂ

    Registry ӥ斉 image 2.ֵአ image ୌ缏
 container 5.Ӥ㯽 image ک Registry 4. 疥ୌᗝঅጱ
 container
 㱪ਂ౮ image 3. ୌᗝ Infrastructure
  10. Docker ฎெ讕螀֢ጱ牫 23 container container image image Docker Registry 1.ℂ

    Registry ӥ斉 image 2.ֵአ image ୌ缏
 container 5.Ӥ㯽 image ک Registry 4. 疥ୌᗝঅጱ
 container
 㱪ਂ౮ image 3. ୌᗝ Infrastructure
  11. ᒫ 1 ೗物玲஑碸猟䲆 (pull) 34 # docker pull [OPTIONS] NAME[:TAG|@DIGEST]

    $ docker pull chusiang/takaojs1607 Using default tag: latest latest: Pulling from chusiang/takaojs1607 20d99f5aec05: Already exists 72f7fcd433f8: Already exists 5dce81f870ab: Already exists a3ed95caeb02: Already exists 23f18164665f: Already exists 282006c4409e: Already exists 3472ef26cc6d: Already exists 16de7d488a57: Already exists a3ed95caeb02: Already exists 5783f1e0c823: Already exists ... Digest: sha256:ce3c8ed58945808496447b9237c3d1e014edebe5c3200901621d73458be9395c Status: Downloaded newer image for chusiang/takaojs1607:latest
  12. ᒫ 2 ೗物ڜڊ๜秚碸猟䲆 (images) 35 # docker images [OPTIONS] [REPOSITORY[:TAG]]

    $ docker images REPOSITORY TAG MAGE ID CREATED SIZE chusiang/takaojs1607 latest 3ad250eb94d2 About an hour ago 1.307 GB takaojs1607 latest 94714eb3e147 2 hours ago 1.307 GB chusiang/gitbook latest 1aa2bbe894cb 8 days ago 696 MB debian latest 1b088884749b 2 weeks ago 125.1 MB centos centos6 6a77ab6655b9 3 weeks ago 194.6 MB ubuntu 14.04 8f1bd21bd25c 4 weeks ago 188 MB memcached latest 8e1d5f409061 7 weeks ago 132.2 MB ubuntu latest b72889fa879c 10 weeks ago 188 MB nginx latest eb4a127a1188 11 weeks ago 182.7 MB debian wheezy ddbdfa5a014a 12 weeks ago 84.89 MB hello-world latest 690ed74de00f 8 months ago 960 B docker/whalesay latest 6b362a9f73eb 13 months ago 247 MB
  13. ᒫ 3 ೗物碝ୌ㪔珸㵕਻瑊 (run) 36 # docker run [OPTIONS] IMAGE

    [COMMAND] [ARG...] # - 3.1. ୌ缏਻瑊㪔珸㵕牧㪔翉ਧ秂伛蜍獈Ӥ牐 # $ docker run -it chusiang/takaojs1607 bash root@fff0cdc8035a:/tmp# exit exit # - 3.2. ֵአ daemon 秇ୗୌ缏਻瑊㪔珸㵕牐 # $ docker run -it -d chusiang/takaojs1607 tail -f /dev/null 473e79f71ed34c3a88cb1def191a241962357952b5c7627b5600... # - 3.3. ୌ缏਻瑊㪔珸㵕牧Ӭ䟑斉๜秚ፓ袅 (local ࣁ獮 container ࣁ盅)牐 # $ docker run -it -v ~/Downloads:/data chusiang/takaojs1607 bash root@cc0345c6ccda:/tmp# exit exit
  14. ᒫ 4 ೗物礚፡਻瑊ᤈ纷 (ps) zz 38 # docker ps [OPTIONS]

    # - 4.1. 礚፡૪珸㵕ጱ containers牐 # $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fff0cdc8035a chusiang/takaojs1607 "tail -f /dev/null" 1 hours ago Up 1 hours cranky_bose # - 4.2. 礚፡ಅ磪ጱ containers牐 # # -a, --all Show all containers (default shows just running) # $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fff0cdc8035a chusiang/takaojs1607 "bash" 1 hours ago Exited (0) 1 hours ago stoic_euler 473e79f71ed3 chusiang/takaojs1607 "tail -f /dev/null" 1 hours ago Up 1 hours cranky_bose
  15. ᒫ 5 ೗物奰ྊ਻瑊 (stop) 39 # docker stop [OPTIONS] CONTAINER

    [CONTAINER...] $ docker stop 473e79f71ed3 473e79f71ed3 $ docker ps # docker start [OPTIONS] CONTAINER [CONTAINER...] $ docker start 473e79f71ed3 473e79f71ed3 $ docker ps ᒫ 6 ೗物珸አ਻瑊 (start)
  16. ᒫ 7 ೗物蝱獈਻瑊 (exec) 41 # docker exec [OPTIONS] CONTAINER

    COMMAND [ARG...] # 礚፡૪珸㵕ጱ containers牐 $ docker ps # 蝱獈 container牐 $ docker exec -it 473e79f71ed3 bash # ෝ container 獉蝱ᤈ砺֢牐 root@473e79f71ed3:/tmp# lsb_release -a > hello_world.txt # 櫝樄 container牐 root@473e79f71ed3:/tmp# exit
  17. ᒫ 8 ೗物൉Ի image (commit) 42 # docker commit [OPTIONS]

    CONTAINER [REPOSITORY[:TAG]] $ docker ps $ docker commit 473e79f71ed3 takaojs1607 sha256:df58b57acb0f10cd8321fa9174becbb19d75463a63354cd11d43debd... $ docker ps # -a, --author string Author # -m, --message string Commit message # $ docker commit -m "൉Ի懱௳" -a "֢ᘏݷ圸" 473e79f71ed3 takaojs1607 sha256:5a2fd19723027fb305beb749ad5114775db8824d4d5d51d89bd04d01...
  18. ᒫ 9 ೗物狕硬秂壆 (tag) 43 # docker tag IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]

    # # ڜڊ匍磪ጱ image牐 $ docker images # 蝚螂 IMAGE ID 狕硬 tag牐 $ docker tag 5a2fd1972302 takaojs1607:1.0 $ docker images # 蝚螂 REPOSITORY ݷ圸狕硬 tag牐 $ docker tag takaojs1607 takaojs1607:1.1 $ docker images $ docker tag takaojs1607:latest takaojs1607:1.2 $ docker images
  19. ᒫ 10 ೗物ᑏᴻ image ޾ tag (rmi) 45 # docker

    rmi [OPTIONS] IMAGE [IMAGE...] # 萞ኧ IMAGE ID ᑏᴻ image牐 $ docker images $ docker rmi 473e79f71ed3 # ᑏᴻ tag牐 $ docker images $ docker rmi takaojs1607:1.2 $ docker image # 䔶ګᑏᴻ (۱珀磪਻瑊ྋࣁ䁆ᤈ)牐 $ docker run hello-world $ docker rmi -f hello-world
  20. ᒫ 11 ೗物ᑏᴻ਻瑊 (rm) 46 # docker rm [OPTIONS] CONTAINER

    [CONTAINER...] $ docker ps -a # ݝᑏᴻ૪؊ྊጱ਻瑊牐 $ docker rm 473e79f71ed3 root@473e79f71ed3:/tmp# # 䔶ګᑏᴻ牐 $ docker rm -f 473e79f71ed3
  21. ᒫ 12 ೗物Ӥ㯽 image (push) 47 # docker push NAME[:TAG]

    [OPTIONS] # # - 襑ጭ獈 Docker Registry ಍ݢֵአ牐 # - Docker Hub: <USERNAME>/<REPO_NAME> # - Private Docker Registry: <SERVER_NAME>/<REPO_NAME> $ docker images $ docker tag 473e79f71ed3 <USERNAME>/foo $ docker tag 473e79f71ed3 <SERVER_NAME>/foo # Ӥ㯽 image $ docker push <USERNAME>foo $ docker push <SERVER_NAME>/foo
  22. 51

  23. 㷢ᘍ෈糽 • Docker Overview - https://docs.docker.com/engine/understanding-docker/ • ̽Docker —— ℂ獈槹ک䋿擅̾ྋ誢Ӿ෈粚

    | GitBook - https://goo.gl/RIN20W • chusiang/takaojs1607-docker-demo: docker demo for takaojs meetup | GitHub
 - https://github.com/chusiang/takaojs1607-docker-demo • selenium/standalone-chrome-debug | Docker Hub - https://goo.gl/hWDwVI • angular/angular-seed | GitHub - https://goo.gl/gWzUJp • start | npm Documentation - https://docs.npmjs.com/cli/start • 獮ᒒᛔ㵕玕介手ԏ Selenium docker 絑ह debug 瞲ܖ | 擽୽ Smlsun
 - http://blog.smlsun.com/2015/04/selenium-docker-debug.html • Docker च器Օ奧膏䋿䜗 - http://www.slideshare.net/appleboy/docker-61214768 61 Free
  24. 瑽粙㬵რ • Find & run the whalesay image | Docker

    Docs - https://goo.gl/NSQmjJ • 岄傀჈率胂犩磪褖獍ݪ-ṛᵜ჈率獤獍ݪ-๜჈膫膨ݱ觊玈率ૡ֢禂ᘏݷ袅 - http://goo.gl/lMOqhW • LCL shipments and container transportation | Flamingo shipping - http://goo.gl/Ouufei • Ի蝢蟂ṛᵜ჈率ੴ - ṛ჈ԏ聅 94 ଙଶᒫԲ䌵硢୽穉搴 - http://goo.gl/ZFjhT0 • Docker Containers and Kubernetes, Smart ecosystem solution to virtualize in the Cloud | Yasser Yassin - https://goo.gl/o8tUfx • Microsoft Announces Docker Command Line Interface for Windows Clients | 1800Pocket/PC - http://goo.gl/fsY1yR • Cloud Backup stew in Docker container? Check – Asigra • The Register - http://goo.gl/Zu955T • Apple Mac Logo Evolution With Apple Mac Startup Sound Evolution 3 - YouTube - https://goo.gl/rXa8Mo • File:Windows logo - 2006.svg - Wikipedia - https://goo.gl/c2zYDh • ᴫ袅Ӟ物޸犤礚扇 |̽Docker —— ℂ獈槹ک䋿擅̾ྋ誢Ӿ෈粚 - https://goo.gl/CVAzZe • How Docker Turbocharged Uber's Deployments | The New Stack - http://goo.gl/EIftQe • AngularJS Meets Salesforce1 - https://scottbcovert.github.io/angularjs-meets-salesforce1/#/2 • "Node.js Logo" Posters by th1341 | Redbubble - http://goo.gl/on0lYO • Now Hiring: QA Engineer w/ Selenium | Boyle Software - http://goo.gl/p3ZdNf 62
  25. END