[ chusiang@takaojs ~ ] $ cat .profile
# 凍仁翔 / chusiang.lai (at) gmail.com / http://note.drx.tw
關於凍仁翔
• 4 年年以上 IT 經驗。
• 現職 DrSays IT ⼯工程師。
• 半年年以上的 Docker 使⽤用經驗。
• 於 Docker Hub 分享的 Images:
• php7
• phpmyadmin
• redis.dockerfile
• gitbook
• vim-and-vi-mode
2
簡報開始
3
Outline
I. 前端⼯工程師是什什麼?
4
Outline
I. 前端⼯工程師是什什麼?
II. 導入虛擬化容器的好處是什什麼?
5
Outline
I. 前端⼯工程師是什什麼?
II. 導入虛擬化容器的好處是什什麼?
III. Docker 是什什麼?
6
Outline
I. 前端⼯工程師是什什麼?
II. 導入虛擬化容器的好處是什什麼?
III. Docker 是什什麼?
IV. 怎麼安裝 Docker?
7
Outline
I. 前端⼯工程師是什什麼?
II. 導入虛擬化容器的好處是什什麼?
III. Docker 是什什麼?
IV. 怎麼安裝 Docker?
V. 12 招成為 Docker ⼤大師!
8
Outline
I. 前端⼯工程師是什什麼?
II. 導入虛擬化容器的好處是什什麼?
III. Docker 是什什麼?
IV. 怎麼安裝 Docker?
V. 12 招成為 Docker ⼤大師!
VI. Q & A
9
Ⅰ. 前端⼯工程師是什什麼?
10
前端⼯工程師是什什麼?
11
• ⼗十八般武藝樣樣都要會的⼈人。
JavaScript
jQuery
RWD
Git
Sublime Text
Vim
HTML5CSS
Node.js
JSON
Firefox
Safari
Chrome
IE
Django
PHP
Laravel
Skitch
Python
UI
UX
Ⅱ. 導入虛擬化容器的好處是什什麼?
12
※ 註:Docker 不是第⼀一個出現的容器 (container) 技術。
導入 Docker 虛擬化容器,
我們可以簡化移交作業流程、
免除重建基礎建設⼯工程、
減少計畫外⼯工作,更更可以
讓開發、測試和正式環境
無縫接軌。
⾼高港之美攝影比賽 - http://goo.gl/ZFjhT0
13
Ⅲ. Docker 是什什麼?
14
Docker 字⾯面上的意思是碼頭⼯工⼈人。
15
從 2014 年年開始,Docker 

都是重要 IT 年年會中最搶⼿手

的攤位之⼀一,與 Docker 有
關的演講也場場爆滿。

Docker 的迅速竄起,不只是因
為 Container 技術本⾝身,更更重
要的關鍵是 Docker 的出現,
引爆了了 IT 架構的新變⾰革。
iThome - http://goo.gl/lJPQLF
16
Docker 是⼀一個集打包、運送和使⽤用容器技術來來執⾏行行應⽤用程式
為⼀一⾝身的開放源始碼專案。
17
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
Docker 是怎麼運作的?
19
container container
image image
Docker
Registry1.從 Registry 下載 image
2.使⽤用 image 建立

container
5.上傳 image 到 Registry
4. 將建置好的

container

儲存成 image
3. 建置 Infrastructure
Docker 是怎麼運作的?
20
container container
image image
Docker
Registry1.從 Registry 下載 image
2.使⽤用 image 建立

container
5.上傳 image 到 Registry
4. 將建置好的

container

儲存成 image
3. 建置 Infrastructure
Docker 是怎麼運作的?
21
container container
image image
Docker
Registry1.從 Registry 下載 image
2.使⽤用 image 建立

container
5.上傳 image 到 Registry
4. 將建置好的

container

儲存成 image
3. 建置 Infrastructure
Docker 是怎麼運作的?
22
container container
image image
Docker
Registry1.從 Registry 下載 image
2.使⽤用 image 建立

container
5.上傳 image 到 Registry
4. 將建置好的

container

儲存成 image
3. 建置 Infrastructure
Docker 是怎麼運作的?
23
container container
image image
Docker
Registry1.從 Registry 下載 image
2.使⽤用 image 建立

container
5.上傳 image 到 Registry
4. 將建置好的

container

儲存成 image
3. 建置 Infrastructure
Ⅳ. 怎麼安裝 Docker?
24
GNU/Linux
25
WindowsmacOS
怎麼在 Ubuntu 安裝 Docker?- http://goo.gl/klHIyP
怎麼在 macOS 安裝 Docker?- http://goo.gl/EcY2YL
怎麼在 Windows 安裝 Docker?- https://goo.gl/pVrGFZ
Ⅴ. 12 招成為 Docker ⼤大師!
29
Terminal and
30
Kitematic
Terminal and Kitematic
Ⅰ
Ⅱ
Ⅲ
Lv1
第 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
第 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
第 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
Ⅳ
Ⅴ
Ⅵ
Lv2
37
第 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
第 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)
Ⅶ
Ⅸ
Ⅷ
Lv3
40
第 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
第 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...
第 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
Ⅺ
Ⅹ
Ⅻ
Lv4
44
第 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
第 11 招:移除容器 (rm)
46
# docker rm [OPTIONS] CONTAINER [CONTAINER...]
$ docker ps -a
# 只移除已停⽌止的容器。
$ docker rm 473e79f71ed3
root@473e79f71ed3:/tmp#
# 強制移除。
$ docker rm -f 473e79f71ed3
第 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
火 ⼒力力 展 ⽰示
Live Demo
48
https://hub.docker.com/r/chusiang/takaojs1607/
https://youtu.be/XqCt8gk9AdI
51
1/3
52
Q & A
嚴禁拍打餵食
54
⼯工商服務
55
56
http://萍⽔水相逢.tw
DevOps Taiwan
https://www.facebook.com/groups/DevOpsTaiwan/
https://devopstaiwan.slack.com/
https://gitter.im/DevOpsTW/
http://www.vim.tw
http://coscup.org
http://mopcon.org
參參考⽂文獻
• 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
圖片來來源
• 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
END

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