Docker - docker images存儲位置,引出ls和du命令的不同


docker鏡像存儲位置

docker info | grep "Docker Root Dir"

例如我的driver是overlay2,則docker鏡像的實際存儲在/var/lib/docker/overlay2文件夾里面。


ls和du的不同

ls -alh dir/顯示文件的大小或文件夾的元數據的大小。所以在ls -alh 文件夾時,元數據存儲在一個block里面,一個block的大小(4.0K),而不顯示里面實際內容的大小。
du顯示當前文件夾的磁盤占有大小。

Summarize disk usage of the set of FILEs, recursively for directories


解決問題的過程 TLDR;

  1. Google一下。找到

https://stackoverflow.com/a/25978888/5955399

  1. 原來存儲位置取決於driver。
  2. 輸入docker info查看,關鍵的信息:Server Version: 18.09.6, Storage Driver: overlay2, Docker Root Dir: /var/lib/docker。我的docker driver是overlay2。
  3. ls -alh /varl/lib/docker/overlay2。咦!為什么都是4.0KB大小?和我的docker images顯示的size不同,明明size有幾G大。
  4. 想起了linux在磁盤上表現為用block去存儲,一個block是4.0KB。ls命令顯示的只是文件夾的meta-data,不是實際內容在磁盤的占有大小。

https://askubuntu.com/questions/186813/why-does-every-directory-have-a-size-4096-bytes-4-k
https://unix.stackexchange.com/questions/55/what-does-size-of-a-directory-mean-in-output-of-ls-l-command?

  1. 怎么查看實際磁盤占有大小?du -s /var/lib/docker/overlay2的最后一行。
    或者du -sh /var/lib/docker/overlay2
    或者更human readable的,根據文件大小排序du -sh * | sort -h

https://unix.stackexchange.com/questions/371238/what-is-the-difference-between-file-size-in-ls-l-and-du-sh
https://stackoverflow.com/questions/1019116/using-ls-to-list-directories-and-their-total-sizes
https://unix.stackexchange.com/questions/185764/how-do-i-get-the-size-of-a-directory-on-the-command-line
https://unix.stackexchange.com/questions/371238/what-is-the-difference-between-file-size-in-ls-l-and-du-sh


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM