惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
S
Securelist
博客园 - Franky
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
IT之家
IT之家
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
The Cloudflare Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
AI
AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Schneier on Security
Schneier on Security
Attack and Defense Labs
Attack and Defense Labs
Vercel News
Vercel News
腾讯CDC
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
Netflix TechBlog - Medium
量子位
S
Schneier on Security
Hacker News: Ask HN
Hacker News: Ask HN
Cyberwarzone
Cyberwarzone
S
Security Affairs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
News and Events Feed by Topic
T
Tenable Blog
PCI Perspectives
PCI Perspectives
MyScale Blog
MyScale Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
W
WeLiveSecurity
N
News | PayPal Newsroom
P
Proofpoint News Feed
O
OpenAI News
C
CERT Recently Published Vulnerability Notes
B
Blog
Cisco Talos Blog
Cisco Talos Blog
Microsoft Security Blog
Microsoft Security Blog
V
Visual Studio Blog
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Spread Privacy
Spread Privacy

博客园 - Don

在Chrome中调试Android微信浏览器中的网页,不出现供选择页面的怎么办?(chrome://inspect/#devices) 使用Crontab集合sh脚本自动删除过期的Confluence Docker容器中的备份文件 Docker PHP中安装gd扩展并生成图形验证码 解决命令行提示“cannot create temp file for here-document: No space left on device”但磁盘使用率并未满的问题 SSH登录后提示LC_ALL: cannot change locale (en_US.UTF8) 的解决办法 解决git操作一直要求输入用户名和密码的问题 CentOS如何增加虚拟内存 RabbitMQ集群脑裂故障处理 zookeeper日志定时清理 Alibaba Centos ECS 安全更新记录 AWS EC2配置CloudWatch 记录AWS Linux2 的yum安全更新步骤 记录Docker系统盘空间占用过大的解决方法 AWS EC2 EBS数据盘挂载与相关日常维护操作 AWS Amazon Linux2 安装Docker和Docker Compose AndroidGetAPKInfo --- 检查包名(packageName)、版本(versionName\versionCode)、应用签名(Signature)等信息 - Don OpenSSL命令—pkcs12 Linux下User与Group的常用操作命令解析 Docker搭建openvpn - Don
[转]提升 Docker Desktop For macOS 磁盘使用率
Don · 2022-04-24 · via 博客园 - Don

提升 Docker Desktop For macOS 磁盘使用率
本篇文章分享一些软件使用上的细节,以及如何提升磁盘利用率。

使用工具镜像和官方命令回收空间
如果你和我一样,使用 macOS 设备依赖容器做开发调试,那么随着时间的推移,会发现 “Docker 应用” 相关进程占用资源越来越多,即使在关闭所有容器应用后,使用 docker system prune 清理也不见效果。

早在几年前,就有人在官方反馈了关于硬盘空间未被正确释放的问题:Docker.qcow2 never shrinks - disk space usage leak in docker for mac #371

一般情况下,解决这个问题的方案只需要两步,先执行下面的命令,触发 Docker 文件系统回收:

docker run --privileged --pid=host docker/desktop-reclaim-space
 
然后再接着执行 docker system prune,稍等片刻即能看到磁盘用量有了明显的减少了。

最后使用 ls 查看文件尺寸,就能够看到尺寸占用被有效的减少啦:

ls -klsh ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw
29654336 -rw-r--r-- 1 soulteary staff 60G 4 24 16:30 /Users/soulteary/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw
 
上面的日志说明我们设置的文件最大尺寸为 60GB,目前已经使用了接近 29GB。

重置应用强制回收空间
如果上面的操作在某些场景下没有生效,我们还可以继续使用应用重置的方式来“解决问题”。

在重置之前,我们还可以对之前使用的数据进行保存,以减少后续使用镜像时,拉取镜像的时间消耗。

当然,这里也可以对镜像打上 Tag,推送到私有仓库中,关于私有仓库的搭建,我之前有提过,感兴趣可以自行翻阅。

批量保存和导入容器镜像
原本想使用网上现成的命令,但是看了下都写的又啰嗦又长,于是忍不住写了“一句话”:

docker images | sed '1d' | grep -v '<none>' | awk '{print "docker save " $1 ":" $2 " -o " $3 ".tar"}' | bash
 
执行脚本后,机器上所有带有明确名称和版本的镜像,都会被以镜像短哈希为名称保存在目录

而导入镜像就更简单了,使用 ls 和 xargs 写一句话命令就完事:

ls *.tar | xargs -I {} docker load -i {}
 
其他
如果经过清理,磁盘占用还是很大,不妨使用 docker system df -v 来看看到底是哪些镜像、应用、网络、数据卷、缓存占用了磁盘:

Images space usage:

REPOSITORY TAG IMAGE ID CREATED SIZE SHARED SIZE UNIQUE SIZE CONTAINERS
soulteary/prebuilt-nginx-modules waf-1.20.0 24c736456f8e 3 hours ago 208.1kB 0B 208.1kB 0
soulteary/prebuilt-nginx-modules srcache-1.20.0 067753cb2b67 3 hours ago 302.3kB 0B 302.3kB 0
soulteary/prebuilt-nginx-modules redis2-1.20.0 9c05e05b2a99 3 hours ago 185.2kB 0B 185.2kB 0
soulteary/prebuilt-nginx-modules memc-1.20.0 fe364267465a 3 hours ago 263kB 0B 263kB 0
soulteary/prebuilt-nginx-modules http-redis-1.20.0 fd0730f838f3 3 hours ago 88.14kB 0B 88.14kB 0
...


Containers space usage:

CONTAINER ID IMAGE COMMAND LOCAL VOLUMES SIZE CREATED STATUS NAMES
7b6d5a4258c0 traefik:v2.3.4 "/entrypoint.sh --gl…" 0 0B 50 minutes ago Up 49 minutes (healthy) traefik
...

Local Volumes space usage:

VOLUME NAME LINKS SIZE

Build cache usage: 0B

CACHE ID CACHE TYPE SIZE CREATED LAST USED USAGE SHARED
 
当然,如果只希望看到哪些镜像比较大,则可以使用下面的命令:

docker images --format '{{.Size}}\t{{.Repository}}\t{{.Tag}}\t{{.ID}}' | sed 's/ //' | sort -h -r | column -t
 
随着 Docker 客户端的更新,有时更新客户端会导致出现一些莫名其妙的问题。为了解决问题,还可以尝试重新下载客户端进行安装:

Intel芯片电脑:https://desktop.docker.com/mac/stable/amd64/Docker.dmg
M1 芯片电脑:https://desktop.docker.com/mac/stable/arm64/Docker.dmg