docker
基本觀念
參考資料
- image 映像檔
- docker image is read-only
- can build the docker container
- 每個 image 有不同的 tag
- Container 容器
- 可以被啟動、開始、停止、刪除
- 每個容器互相獨立,不會互相影響
- Repository 倉庫
- 集中存放 image 的地方,內含多個 image
- 兩種形式: public and private
VM vs. Docker
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
參考資料
VM
- 優點
- VM 各自擁有自己的 OS kernel
- 不同的環境可以並存
同一台 VM 可以同時安裝 Windows and Linus,但是套件安裝只能統一版本
- 缺點
- VM 複製環境的速度比較慢
因為 image = 整台 VM ,所以檔案較大
docker
- 優點
- 多個 containers 彼此之間共一個 OS kernel
- Docker 不能同時安裝 Windows and Linux,只能擇一 (優缺?)
但是不同的 Container 可以安裝不同的環境,彼此不干擾。
- ex: Container_1 install python 3.6.9 and Container_2 install python 3.8
- 執行不會因為 Container 彼此版本不同而衝突
- 相同的硬體資源,Docker 可以執行較多單位
- Docker 複製環境的速度比較快
因為每一個 Container 都有自己的 image,若要複製特定一個 image 會比 VM 快。
- 缺點
- install
- docker-compose.yml 範本內容
docker-compose 範例內容
- 啟動所有的 docker container
- 切到和 docker-compose.yml 同一層路徑,查看 Docker Container 的執行狀態
docker 架站/基礎指令
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
教學影片
需要條件
requirement.txt
- 檔案中所有需要用到的套件寫成
requirement.txt
- 寫入後端有安裝的套件名稱以及版本
- 每次更新套件,docker 要重新佈署
dockerfile
- 引入後端對應的套件
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
docker image python
示意圖
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
run.ini
示意圖
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- docker-compose.yml (optional)
示意圖
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 如果服務有更動,3 個地方要改
- domain name
- 網址(mask -> gei)
- docker-compose.yml
事先準備
- 確認上面的需要條件都有建立
- docker dns check:確認申請的網址是不是 public
建立服務
docker build -t <服務名稱> .
服務建立
docker-compose up -d
讓服務跑起來
docker ps -a
確認有沒有跑起來
docker logs <docker image name>
查看 docker 的 log
- 跑完要刪除 image (
<none>
):把原本系統的 image (像是檔案格式 .png…)刪除
docker image prune
docker images
查看目前的 image

docker stop <服務名稱>
停止服務
之後更新網站上去
- 我們架設網站的地方

可以參考的 docker 教學