Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
讓軟體開發與應用更自由 - 使用 Docker 容器技術
Search
Yu-Lung Shao
June 25, 2017
Programming
1
78
讓軟體開發與應用更自由 - 使用 Docker 容器技術
20170625 台中自由軟體愛好者社群
#Docker
#LaraDock
Yu-Lung Shao
June 25, 2017
Tweet
Share
Other Decks in Programming
See All in Programming
Flutterで備える!Accessibility Nutrition Labels完全ガイド
yuukiw00w
0
140
Azure AI Foundryではじめてのマルチエージェントワークフロー
seosoft
0
150
ソフトウェア品質を数字で捉える技術。事業成長を支えるシステム品質の マネジメント
takuya542
0
540
WebViewの現在地 - SwiftUI時代のWebKit - / The Current State Of WebView
marcy731
0
110
0626 Findy Product Manager LT Night_高田スライド_speaker deck用
mana_takada
0
140
Code as Context 〜 1にコードで 2にリンタ 34がなくて 5にルール? 〜
yodakeisuke
0
120
Discover Metal 4
rei315
2
110
High-Level Programming Languages in AI Era -Human Thought and Mind-
hayat01sh1da
PRO
0
690
Hypervel - A Coroutine Framework for Laravel Artisans
albertcht
1
110
PicoRuby on Rails
makicamel
2
120
Team topologies and the microservice architecture: a synergistic relationship
cer
PRO
0
1.2k
Systèmes distribués, pour le meilleur et pour le pire - BreizhCamp 2025 - Conférence
slecache
0
120
Featured
See All Featured
The Cult of Friendly URLs
andyhume
79
6.5k
Done Done
chrislema
184
16k
The World Runs on Bad Software
bkeepers
PRO
69
11k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
138
34k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.8k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
Building Adaptive Systems
keathley
43
2.6k
Visualization
eitanlees
146
16k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
We Have a Design System, Now What?
morganepeng
53
7.7k
Designing for Performance
lara
609
69k
Faster Mobile Websites
deanohume
307
31k
Transcript
讓軟體開發與應⽤用更更⾃自由 使⽤用 docker 容器技術 2017.06.25 @台中⾃自由軟體愛好者社群(TFC)
講者 • 邵⽟玉龍 (Allen Shao) • 網路路暱稱:bestlong • 在⼿手⼯工具製造公司內擔任資訊⼈人員 •
程式開發、系統維運 • 持續學習探索 DevOps 中
⼤大綱 • Docker 基本概念念 • PHP 開發者的環境演變 • 會介紹 LaraDock
• 命令列列打字好累有沒有更更⽅方便便的管理理⼯工具 • Docker 使⽤用空間⼤大掃除
Docker 基本概念念
什什麼是 Docker? • Software Container Platform • Application delivery technology
• Not VMs • 比較像是隔離環境與共享資源⽽而不是模擬 • 獨棟房屋 vs 多住⼾戶公寓 Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications, whether on laptops, data center VMs, or the cloud.
Docker vs VM 圖片來來源 https://www.docker.com/what-container
VM Docker Size ⼤大 ⼩小 Startup 慢 快 Integration 不易易
容易易 簡單比較
Docker with VM 圖片來來源 https://www.docker.com/what-container
Why docker • Developer • 可以解決只在我的電腦可以正常運作的囧況 • 多⼈人協同開發讓開發環境統⼀一 • 新成員快速建置環境
• 經常要切換新舊環境版本 • Operator (System Admin) • build, ship, test, and deploy apps ⾃自動化 • Enterprise • DevOps, agile • cloud-ready, optimal costs
Docker Editions • Docker CE (Community Edition) • Stable •
Edge • Docker EE (Enterprise Edition) • Basic • Standard • Advanced • Moby ? • https://mobyproject.org/
Support Platform • Linux • apt-get install docker.io • macOS
• 舊版⽤用 boot2docker • Windows • 舊版⽤用 boot2docker • Win10 x64
Docker Engine 圖片來來源 https://docs.docker.com/engine/docker-overview/
• 三個基本要素 • Image 映像檔 • Container 容器 • Registry
(Repostory 倉庫) • 兩兩個基本必要 • 網路路 • ⾜足夠的硬碟空間
先來來感覺⼀一下 • 沒有環境的可先使⽤用線上服務 http://play-with-docker.com/ • docker version • docker info
• docker ps • docker images • docker pull hello-world • docker run hello-world • docker run -it ubuntu bash
Docker architecture Volumes dockerfile Client/Server 架構 圖片來來源 https://docs.docker.com/engine/docker-overview/
Docker 映像檔 • 唯讀的模板 • 分層結構,有層數上限 • 建立 Container 的模版
• Docker Hub https://hub.docker.com/
Docker 映像檔 分層結構圖⽰示 圖片來來源 https://blog.jayway.com/2015/03/21/a-not-very-short-introduction-to-docker/
Dockerfile • 打造映像檔的藍藍圖 • 需要具備 Linux 系統管理理的知識
Dockerfile commands • 命令有效範圍區分為建構時期與啟動容器時期 Build Both (Build/Run) Run FROM MAINTAINER
COPY ADD RUN ONBUILD .dockerignore WORKDIR USER CMD ENV EXPOSE VOLUME ENTRYPOINT https://docs.docker.com/engine/reference/builder/ 第⼀一個指令必須為 ‘FROM’
Dockerfile 設計原則 • 先求正確建構 • ⼀一個指令⼀一個 RUN • 再進⾏行行最佳化 •
減少映像檔分層 • ⽤用 && 合併 RUN 指令 • 容量量最⼩小化 • 不需要的檔案不要 ADD (應⽤用 .dockerignore) • 刪除暫存檔
Demo
PHP 開發者的⼯工作環境演變 使⽤用 HTTP + PHP + DB 組合
• Windows 開發環境 • ⼿手動安裝 • XAMPP • WampServer •
AppServ • 多重開機進入 Linux 環境 • 步驟繁瑣、版本固定 開發 PHP 演進 - 本機
開發 PHP 演進 - 遠端主機 • 在家中或公司架設主機 • Linux ⽤用
telnet, ssh, VNC 連入 • Windows ⽤用遠端桌⾯面連入 • 必須要有網路路
開發 PHP 演進 - 本機VM • VMware • VirtualBox •
Vargrant • ⽤用 vargrantfile ⾃自動化安裝、設定、管理理多個VM • 虛擬磁碟很佔⽤用空間 • VM 很耗資源,需要較⾼高階的電腦
開發 PHP 演進 - 本機容器 • docker 單⼀一容器全包 • 適合開發與測試,效能差
• docker 多個容器分散架構 • 指令太繁瑣,要對 Docker Network 熟悉 • docker-compose 多容器的管理理⼯工具 • 適合開發與⽣生產環境 • 預設設定檔 docker-compose.yml • 介紹使⽤用 LaraDock http://laradock.io/
Demo
命令列列打字好累有沒有 更更⽅方便便的管理理⼯工具
更更⽅方便便的管理理⼯工具 • GUI • Kitematic (MacOS、Windows) https://kitematic.com/ • WebUI •
Portainer https://portainer.io/ • Shipyard https://shipyard-project.com/ • Rancher http://rancher.com/rancher/ • Kubernetes https://kubernetes.io/
Docker 使⽤用空間⼤大掃除
Docker 玩著玩著就佔⽤用了了很多的硬 碟空間 • 三個需要清理理的部分 • 容器 • 映像檔 •
Volume • 強制釋放佔⽤用空間 (macOS)
清理理容器 刪除指定執⾏行行中容器 docker rm CONTAINER 刪除全部執⾏行行中容器 docker kill $(docker ps
-q) 刪除所有容器 docker rm $(docker ps -aq) 強制刪除所有容器 docker rm -f $(docker ps -aq) 刪除已停⽌止的容器 docker rm $(docker ps -aq -f status=exited) 請⼩小⼼心使⽤用:刪除容器會遺失讀寫層的資料 過濾條件請參參考 https://docs.docker.com/engine/reference/ commandline/ps/#filtering
清理理映像檔 刪除指定映像檔 docker rmi IMAGE 刪除沒有建立容器的映像檔 docker rmi $(docker images
-q) 刪除沒有TAG的映像檔 docker rmi -f $(docker images -q -f dangling=true) 過濾條件請參參考 https://docs.docker.com/engine/reference/ commandline/images/#filtering
清理理 Volume 刪除孤兒 volume docker volume rm $(docker volume ls
-q -f dangling=true) 強制刪除所有 volume docker volume rm -f $(docker volume ls -q) 請⼩小⼼心使⽤用:刪除 volume 會遺失資料 過濾條件請參參考 https://docs.docker.com/engine/reference/ commandline/volume_ls/#filtering
強制釋放佔⽤用空間 (macOS) OOXX 該刪的都刪了了,怎麼 Host OS 磁碟空間還是沒釋放? 反正都刪光了了,試試看跑 Reset to
factory defaults
總結 • Docker 能更更快速的建置開發或⽣生產環境 • 讓系統架構即為程式碼 • 開發者學到 docker-compose 階段就很⾜足夠了了
• Volume ⼀一定要弄弄清楚,避免發⽣生資料遺失事件
學習資源 • https://docs.docker.com/ • Docker — 從入⾨門到實踐 • https://www.gitbook.com/explore
Q&A