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;
- Google一下。找到
- 原來存儲位置取決於driver。
- 輸入
docker info
查看,關鍵的信息:Server Version: 18.09.6, Storage Driver: overlay2, Docker Root Dir: /var/lib/docker。我的docker driver是overlay2。 ls -alh /varl/lib/docker/overlay2
。咦!為什么都是4.0KB大小?和我的docker images顯示的size不同,明明size有幾G大。- 想起了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?
- 怎么查看實際磁盤占有大小?
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