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

Docker 初探,實驗室中的運貨鯨

Docker 初探,實驗室中的運貨鯨

http://blog.fntsr.tw/articles/2015/05/28/docker-talks-on-ncu/

學校實驗室總會有些需求,架設各種服務,例如:Redmine、MySQL、Wiki、GitLab ...
以往我們都會一股腦將這些服務架設在同一主機,或是各開一台虛擬機器,放在裡面,
然後就一屆傳一屆,只要不要掛掉就繼續使用。

但到了某天,發現舊版有漏洞,或是新版有更好用的功能,
才又挖出更新說明,辛辛苦苦的將各種服務一一更新上線。
又或是老闆要求架新服務,但才發現因為虛擬機器開太多 IP 不夠用了,
只好再度將各個服務都塞在同一台電腦裡,失去原本一台機器一個服務的用意。

有沒有什麼辦法去改善這種窘境?
或是有沒有更快的方式能方便我們部署我們需要的服務?
我想,Docker 或許就是你想要的答案。

「Build, Ship, Run Any App, Anywhere」—— Docker 如是說。

有別於虛擬機器的沈重,輕量的虛擬化技術 Container 正夯,
本講座將帶聽眾認識 Docker —— 一個方便操作 Container 的工具,
讓你以更方便、更快速的方式,管理你實驗室上的各個服務。

Ruoshi Ling

May 28, 2015
Tweet

More Decks by Ruoshi Ling

Other Decks in Technology

Transcript

  1. ꡠ倴䧮糵 넞♧ ✳겳穉 ♲겳穉 娜〷㷸禺 鮿넓䊨玑 灇瑖䨾 ↛㡨珮䰟䲲 䛧テ 䠀䕊

       ℎ 哩 Ⰸ ⹙ 㡨 縠 涹 ℎ ℎⰏ Ⰸ⹙  䛟⨉∮剏
  2. ꡠ倴䧮糵 NCHU EECSeC 哩
 Ⰸ
 ⹙
 䠀
 㧤
 羝
 峫


    揉 哩
 Ⰸ
 槜 羝 ⛭ 痙 䰟 劅 䥝群↛ 㥲㨀⻇劳䠀 ⒁憮楫⇮
  3. *OTUBMM%PDLFSPO6CVOUV 4BVDZ 5SVTUZ -54 1SFDJTF -54 ,FSOFM *OTUBMM QSFSFRVJTJUFT &YFDVUF

    DPNNBOE $  wget  -­‐qO-­‐  https://get.docker.com/  |  sh 5WRRQTV 8GTUKQP
  4. $ docker Commands: attach Attach to a running container build

    Build an image from a Dockerfile commit Create a new image from a container's changes $  docker 㛇燊䭸⟂ #BTJD$PNNBOE
  5. $ docker version Client version: 1.62 Client API version: 1.18

    Go version (client): go1.4.1 Git commit (client): a8a31ef OS/Arch (client): darwin/amd64 Server version: 1.6.2 Server API version: 1.18 Go version (server): go1.4.2 Git commit (server): 4749651 $  docker  version 㛇燊䭸⟂ #BTJD$PNNBOE 嗆5GTXGT羝峫㽳ⓛ䛟 孉䰛㽳㧪桬界珮聏倱㓱▀
  6. $ docker info Containers: 3 Images: 65 Storage Driver: aufs

    Root Dir: /mnt/sda1/var/lib/docker/aufs … Execution Driver: native-0.2 Kernel Version: 4.0.3-boot2docker Operating System: Boot2Docker 1.6.2 (TCL 5.4); …… $  docker  info 㛇燊䭸⟂ #BTJD$PNNBOE
  7. $ docker run --help Usage: docker run [OPTIONS] IMAGE [COMMAND]

    [ARG...] Run a command in a new container …… $  docker  command  -­‐-­‐help 㛇燊䭸⟂ #BTJD$PNNBOE
  8. $ docker run ubuntu:14.04 /bin/echo 'Hello world' Hello world 痧♧佅%PDLFSJ[F䥰欽玑䒭

    %PDLFSJ[JOH"QQMJDBUJPOT")FMMPXPSME $  docker  run  image  execute  [argument,  …]
  9. $ docker run -d ubuntu:14.04 /bin/echo \ 
 -c "while

    true; do echo hello world; sleep 1; done" 1e5535038e285177d5214659a068137486f96ee5c2e85a4ac52dc83f2ebe4147 痧♧佅%PDLFSJ[F䥰欽玑䒭 %PDLFSJ[JOH"QQMJDBUJPOT")FMMPXPSME $  docker  run  -­‐d  image  execute  [argument,  …] #&CGOQPK\GF*GNNQYQTNF
  10. $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES

    1e5535038e28 ubuntu:14.04 /bin/sh… 2 minutes ago Up 1 minute insane_babbage 痧♧佅%PDLFSJ[F䥰欽玑䒭 %PDLFSJ[JOH"QQMJDBUJPOT")FMMPXPSME $  docker  ps #&CGOQPK\GF*GNNQYQTNF
  11. $ docker logs 1e5535038e28 hello world hello world hello world

    痧♧佅%PDLFSJ[F䥰欽玑䒭 %PDLFSJ[JOH"QQMJDBUJPOT")FMMPXPSME $  docker  logs  [container  ID/Name] #&CGOQPK\GF*GNNQYQTNF
  12. $ docker logs insane_babbage hello world hello world hello world

    痧♧佅%PDLFSJ[F䥰欽玑䒭 %PDLFSJ[JOH"QQMJDBUJPOT")FMMPXPSME $  docker  logs  [container  ID/Name] #&CGOQPK\GF*GNNQYQTNF
  13. $ docker run -d -P nginx:latest Unable to find image

    'nginx:latest' locally latest: Pulling from nginx 39bb80489af7: Pull complete …… 72d73c46937a: Pull complete Status: Downloaded newer image for nginx:latest 23e601370946fc9fbdfd6204e1bf70e88e6c18078a0c6ee8640acd2e6694b645 㺂㐼 8PSLJOHXJUI$POUBJOFST $  docker  run  -­‐d  -­‐P  image  execute  [argument,  …] 2QTV
  14. $ docker ps CONTAINER ID IMAGE COMMAND STATUS PORTS 23e601370946

    nginx:latest "nginx … Up 1 minute 0.0.0.0:32768->443/tcp
 0.0.0.0:32769->80/tcp $  docker  ps 㺂㐼 8PSLJOHXJUI$POUBJOFST 2QTV
  15. $ docker ps CONTAINER ID IMAGE COMMAND STATUS PORTS 40dd6835e358

    nginx:latest "nginx … Up 1 minute 443/tcp
 0.0.0.0:32770->80/tcp $  docker  ps 㺂㐼 8PSLJOHXJUI$POUBJOFST 2QTV
  16. $ docker ps CONTAINER ID IMAGE COMMAND STATUS PORTS 40dd6835e358

    nginx:latest "nginx … Up 1 minute 443/tcp
 0.0.0.0:10080->80/tcp $  docker  ps 㺂㐼 8PSLJOHXJUI$POUBJOFST 2QTV
  17. $ docker run -d -P nginx:latest Unable to find image

    'nginx:latest' locally latest: Pulling from nginx 39bb80489af7: Pull complete …… 72d73c46937a: Pull complete Status: Downloaded newer image for nginx:latest 23e601370946fc9fbdfd6204e1bf70e88e6c18078a0c6ee8640acd2e6694b645 㺂㐼 8PSLJOHXJUI$POUBJOFST $  docker  run  -­‐d  -­‐P  image  execute  [argument,  …] 2QTV
  18. $ docker ps CONTAINER ID IMAGE COMMAND STATUS PORTS 23e601370946

    nginx:latest "nginx … Up 1 minute 0.0.0.0:32768->443/tcp
 0.0.0.0:32769->80/tcp $  docker  ps 㺂㐼 8PSLJOHXJUI$POUBJOFST 2QTV
  19. $ docker ps CONTAINER ID IMAGE COMMAND STATUS PORTS 40dd6835e358

    nginx:latest "nginx … Up 1 minute 443/tcp
 0.0.0.0:32770->80/tcp $  docker  ps 㺂㐼 8PSLJOHXJUI$POUBJOFST 2QTV
  20. $ docker ps CONTAINER ID IMAGE COMMAND STATUS PORTS 40dd6835e358

    nginx:latest "nginx … Up 1 minute 443/tcp
 0.0.0.0:10080->80/tcp $  docker  ps 㺂㐼 8PSLJOHXJUI$POUBJOFST 2QTV
  21. $ docker stop nginx_container nginx_container $  docker  stop  [container  ID/Name]

    㺂㐼 8PSLJOHXJUI$POUBJOFST 5VCTVTGUVCTVUVQRMKNN
  22. $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES

    $  docker  ps 㺂㐼 8PSLJOHXJUI$POUBJOFST 5VCTVTGUVCTVUVQRMKNN
  23. $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS

    NAMES 23e601370946 nginx:latest "nginx … 2 minutes ago EXITED(0) nginx_container $  docker  ps  -­‐a 㺂㐼 8PSLJOHXJUI$POUBJOFST 5VCTVTGUVCTVUVQRMKNN
  24. $ docker start nginx_container nginx_container $  docker  start  [container  ID/Name]

    㺂㐼 8PSLJOHXJUI$POUBJOFST 5VCTVTGUVCTVUVQRMKNN
  25. $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES

    23e601370946 nginx:latest "nginx … 10 minutes ago Up 1 minute nginx_container 痧♧佅%PDLFSJ[F䥰欽玑䒭 %PDLFSJ[JOH"QQMJDBUJPOT")FMMPXPSME $  docker  ps
  26. $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES

    23e601370946 nginx:latest "nginx … 15 minutes ago Up 1 minute insane_babbage 痧♧佅%PDLFSJ[F䥰欽玑䒭 %PDLFSJ[JOH"QQMJDBUJPOT")FMMPXPSME $  docker  ps
  27. $ docker stop nginx_container nginx_container $ docker kill nginx_container nginx_container

    $  docker  kill  [container  ID/Name] 㺂㐼 8PSLJOHXJUI$POUBJOFST 5VCTVTGUVCTVUVQRMKNN
  28. $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS

    NAMES $  docker  ps  -­‐a 㺂㐼 8PSLJOHXJUI$POUBJOFST 5VCTVTGUVCTVUVQRMKNN
  29. $ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE

    nginx latest a785ba7493fd 16 hours ago 132.9 MB $  docker  images 僦⫹墂 8PSLJOHXJUI%PDLFS*NBHFT ⓸ⓛ
  30. $ docker pull mysql:latest latest: Pulling from mysql 7a3e804ed6c0: Pull

    complete …… ff78d9bb5f46: Already exists Status: Downloaded newer image for mysql:latest $  docker  pull  image_name:tag 僦⫹墂 8PSLJOHXJUI%PDLFS*NBHFT 㖪甩
  31. $ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE

    nginx latest a785ba7493fd 16 hours ago 132.9 MB mysql latest ff78d9bb5f46 3 days ago 282.9 MB $  docker  images 僦⫹墂 8PSLJOHXJUI%PDLFS*NBHFT ⓸ⓛ
  32. $ docker rmi mysql:latest Untagged: mysql:latest Deleted: ff78d9bb5f46b3a619310a8e3f3e62b98ce08b476d0d5d4088f1853d604f8218 …… Deleted:

    7a3e804ed6c015465a6cb957d032276dbff7ba8582153c38b83acd70ffdad0c6 $  docker  rmi  image_name:tag|image_id 僦⫹墂 8PSLJOHXJUI%PDLFS*NBHFT ┋楅
  33. %PDLFS$PNQPTF #  curl  -­‐L  https://github.com/docker/compose/releases/……  >  /usr/local/bin/docker-­‐compose   #  chmod

     +x  /usr/local/bin/docker-­‐compose $  sudo  pip  install  -­‐U  docker-­‐compose *OTUBMMWJB$63- *OTUBMMWJBQJQ
  34. $ docker-compose up -d Creating swl_service_1… $ docker-compose up -d

    Recreating swl_service_1… $ docker-compose up -d --no-recreate $  docker-­‐compose  up  -­‐d %PDLFS$PNQPTF 61 ㇛䶬猺撮㇛猻珮界▶
  35. $ docker-compose rm No stopped containers $ docker-compose stop &&

    docker-compose rm Going to remove swl_service_1 Are you sure? [yN] y Removing swl_service_1... $  docker-­‐compose  rm %PDLFS$PNQPTF ┋楅ビ⌽㹃䥥⺚⥉