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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Yu-Lung Shao
June 25, 2017
Programming
87
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
讓軟體開發與應用更自由 - 使用 Docker 容器技術
20170625 台中自由軟體愛好者社群
#Docker
#LaraDock
Yu-Lung Shao
June 25, 2017
Other Decks in Programming
See All in Programming
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
0
100
act2-costs.pdf
sumedhbala
0
110
関数型プログラミングのメリットって何だろう?
wanko_it
0
170
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.3k
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
140
技術記事、 専門家としてのプログラマ、 言語化
mizchi
14
7.4k
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
800
SLOをサービス品質の共通言語にするために 取り組んできたこと
wakana0222
0
480
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
7
1.8k
コーディングルールの鮮度を保ちたい for SRE NEXT 2026 / keep-fresh-go-internal-conventions-sre-next-2026
handlename
0
140
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
150
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
510
Featured
See All Featured
How to Ace a Technical Interview
jacobian
281
24k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
190
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
390
Automating Front-end Workflow
addyosmani
1370
210k
How to train your dragon (web standard)
notwaldorf
97
6.7k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Git: the NoSQL Database
bkeepers
PRO
432
67k
[SF Ruby Conf 2025] Rails X
palkan
2
1.2k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
260
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
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