iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 13
1
DevOps

現代化小白也要嘗試的容器手札系列 第 13

Day13. Docker Container 操作日常

鬆獅容器小白13連拍

https://ithelp.ithome.com.tw/upload/images/20201005/20025481OGFgTXMi6c.jpg

Container 操作日常

Image本身是由一層層的layer堆疊組成上來,從linux內核開始疊層架屋,從docker倉庫中pull抓下Image是由Dockerfile來生成,此Image本身只有唯讀不能夠修改。
Container是透過Images生成運作而來,可想像上述疊層概念為Container在Images上疊一層,只不過Container層是可以進行讀寫。

當利用docker run來建立容器時,Docker在後台執行一系列動作

  1. 檢查本地是否存在指定的映像檔,不存在就從公有倉庫下載
  2. 利用映像檔建立並啟動一個容器
  3. 分配一個檔案系統,並在唯讀的映像檔層外面掛載一層可讀寫層
  4. 從宿主主機設定的網路橋界面中橋接一個虛擬埠到容器中去
  5. 從位址池中設定一個 ip 位址給容器
  6. 執行使用者指定的應用程式
  7. 執行完畢後容器被終止

https://ithelp.ithome.com.tw/upload/images/20200919/20025481LgQ92uqbse.png

列出容器清單
Container ID:容器 ID。
Image:使用的映像。
Created:容器的建立時間。
Names:自訂的容器名稱。
Status: 容器狀態。

  • created(已建立)
  • restarting(重啟中)
  • running(運作中)
  • removing(移轉中)
  • paused(暫停)
  • exited(停止)
  • dead(死掉)
  • Ports:容器端口訊息與連接溝通類型(TCP / UDP)。

docker ps 不指定參數就是列出當前的容器
https://ithelp.ithome.com.tw/upload/images/20200919/20025481c4PX6u95Ke.png

docker ps -a 顯示出所有執行中或未執行的容器。
https://ithelp.ithome.com.tw/upload/images/20200919/20025481DmGWHascUK.png

docker ps -n 2 列出最近建立出的兩個容器。
https://ithelp.ithome.com.tw/upload/images/20200919/200254813E6P7gOeli.png

docker ps -s -n 2 列出最近建立出的兩個容器以及各容器空間大小。
https://ithelp.ithome.com.tw/upload/images/20200919/20025481wY8LahSwpy.png

docker ps -q -n 2 僅列出建立的兩個容器ID。
https://ithelp.ithome.com.tw/upload/images/20200919/20025481Vy0SMz4qQP.png

查看個別容器本身配置紀錄
取得指定容器或映像檔的原始資訊本身,其中反饋JSON文件,裡面紀錄著容器配置和狀態資訊。
內容結構化資料如:版本、相關說明、檢索等...用於組織、描述、檢索、保存與知識資源
Docker inspect Container ID
https://ithelp.ithome.com.tw/upload/images/20200919/20025481ZSe7n7gD1h.png
https://ithelp.ithome.com.tw/upload/images/20200919/20025481GtpDVyuATy.png
https://ithelp.ithome.com.tw/upload/images/20200919/20025481drDL3FJeMV.png

用來顯示容器使用的系統資源。不帶任何選項執行 docker stats 命令
stats每隔1秒更新一次輸出內容直到手動按下ctrl + c
以下是顯示輸出的主要內容:

  • Container:短格式顯示容器ID。
  • CPU%:百分比形式顯示處理器用量狀況。
  • MEM Usage/Limit:當前與最大使用的記憶體空間。
  • MEM%:百分比形式顯示記憶體用量狀況。
  • NET I/O:網路I/O資訊。
  • BLOCK I/O:磁碟I/O資訊。
  • PIDS:PID 容器建立的Process ID。

docker stats 顯示目前容器使用的系統資源
https://ithelp.ithome.com.tw/upload/images/20200919/20025481qus4EDyNhi.png

docker stats -a 顯示執行中或非執行的容器的系統資源
https://ithelp.ithome.com.tw/upload/images/20200919/20025481grX8LUnsFu.png

docker stats --no-stream 如不想持續監控容器資源狀況,只輸出當前容器狀態
https://ithelp.ithome.com.tw/upload/images/20200919/20025481Dfd5MklofI.png
docker stats --no-stream b6b430abe6f4 同上述,如果僅想監看指定的一個或多個容器
https://ithelp.ithome.com.tw/upload/images/20200919/20025481hFRdKROwWJ.png


上一篇
Day12. Dockerfile 語法深入探討
下一篇
Day14. Docker Registry on GCR 實測
系列文
現代化小白也要嘗試的容器手札30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言