Update from Sync Service
This commit is contained in:
@@ -1,2 +1,62 @@
|
||||
1. **大量****镜像通过命令 docker image prune -f 清理。**
|
||||
2. **通过命令 docker images | awk 'NR!=1{print $1":"$2}' | xargs docker rmi 可以批量清除无用的镜像,且不会影响使用中的镜像和基础镜像,满足笔者的需求。** > 来自 <[https://www.cnblogs.com/sqgzy/p/11864675.html](https://www.cnblogs.com/sqgzy/p/11864675.html)> > 来自 <[https://www.cnblogs.com/sqgzy/p/11864675.html](https://www.cnblogs.com/sqgzy/p/11864675.html)>
|
||||
# Docker 镜像清理
|
||||
|
||||
## 清理无用镜像
|
||||
|
||||
### 方法一:prune 命令(推荐)
|
||||
|
||||
```bash
|
||||
# 清理悬空镜像(无 tag 的镜像)
|
||||
docker image prune -f
|
||||
|
||||
# 清理所有未使用镜像
|
||||
docker image prune -a -f
|
||||
```
|
||||
|
||||
### 方法二:批量清理
|
||||
|
||||
```bash
|
||||
# 批量删除所有无用镜像,不会影响正在使用的镜像
|
||||
docker images | awk 'NR!=1{print $1":"$2}' | xargs docker rmi
|
||||
```
|
||||
|
||||
### 方法三:system prune(全面清理)
|
||||
|
||||
```bash
|
||||
# 清理所有未使用的容器、网络、镜像
|
||||
docker system prune -f
|
||||
|
||||
# 清理所有未使用的镜像,不仅仅是悬空镜像
|
||||
docker system prune -a -f
|
||||
|
||||
# 清理卷(注意:会删除数据)
|
||||
docker system prune --volumes -f
|
||||
```
|
||||
|
||||
## 清理前后对比
|
||||
|
||||
```bash
|
||||
# 查看清理前
|
||||
docker images -a
|
||||
|
||||
# 清理
|
||||
docker system prune -f
|
||||
|
||||
# 查看清理后
|
||||
docker images -a
|
||||
```
|
||||
|
||||
## 定时清理(可选)
|
||||
|
||||
创建 cron 任务定期清理:
|
||||
|
||||
```bash
|
||||
# 编辑 crontab
|
||||
crontab -e
|
||||
|
||||
# 每周日凌晨 3 点清理
|
||||
0 3 * * 0 /usr/bin/docker system prune -f
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> 参考:[Docker 官方文档](https://docs.docker.com/config/pruning/)
|
||||
|
||||
Reference in New Issue
Block a user