為什么選擇容器
- 節(jié)省資源,輕量級(jí),啟動(dòng)速度快
-
隔離性強(qiáng)
image.png
容器基礎(chǔ)
- Container runtime:能夠基于在線獲取的鏡像來(lái)創(chuàng)建和運(yùn)行容器的程序,docker是最熟悉的container runtime
-
docker架構(gòu)image.png
Image跟container的關(guān)系好比面向?qū)ο缶幊讨械念惡蛯?shí)例,image是靜態(tài)定義,container是運(yùn)行實(shí)例
-
容器image
Docker image是一個(gè)層級(jí)文件系統(tǒng)(unionfs)
一個(gè)典型的Linux文件系統(tǒng)由bootfs以及rootfs構(gòu)成,其中bootfs用于加載Linux kernel,而rootfs包含Linux 系統(tǒng)中的/dev,/proc,/bin,/etc 等標(biāo)準(zhǔn)目錄和文件
傳統(tǒng)的 Linux 加載 bootfs 時(shí)會(huì)先將 rootfs 設(shè)為 read-only,然后在系統(tǒng)自檢之后將 rootfs 從 read-only 改為 read-write,然后我們就可以在 rootfs 上進(jìn)行讀寫操作
但 Docker 在 bootfs 自檢完畢之后并不會(huì)把 rootfs 的 read-only 改為 read-write,而是利用union mount技術(shù)將 image 中的其他的 layer 加載到之前的 read-only 的 rootfs 層之上,每一層 layer 都是 rootfs 的結(jié)構(gòu),并且是read-only 的
所以,我們是無(wú)法修改一個(gè)已有鏡像里面的 layer 的!只有當(dāng)我們創(chuàng)建一個(gè)容器,也就是將 Docker 鏡像進(jìn)行實(shí)例化,系統(tǒng)會(huì)分配一層空的 read-write 的 rootfs ,用于保存我們做的修改
image.png


