1. 清理存在但未使用的资源
[root@test ~]# docker system prune
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all dangling build cache
Are you sure you want to continue? [y/N]
2. 镜像清理
Remove unused images
[root@test ~]# docker image prune
-a, --all Remove all unused images, not just dangling ones
[root@test ~]# docker image prune -a
3. Remove all stopped containers
docker container prune
4. 查看资源磁盘占用率
[root@test ~]# docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 27 27 14.16GB 3.654GB (25%)
Containers 34 34 796.1MB 0B (0%)
Local Volumes 13 5 8.089GB 554.1MB (6%)
Build Cache 0 0 0B 0B
查看某个容器占用磁盘特别大
- 查看docker container
[root@test ~]# docker info |grep Dir
Docker Root Dir: /data/docker
[root@liuming_xd25 containers]# pwd
/data/docker/containers
[root@liuming_xd25 containers]# du -sh * |grep G
1.9G 33f6e2043842568f4cf99dbf1ef405f8717c7a3ed1fea4fe79ab331cbd85bebd
1.3G 6404f6568d1d37d29e41b94b0bc05697f677f6269ee039edd30161935437dd6a
# 容器下有*-json.log 文件,清空该文件
echo > {}-json.log
- 修改docker配置,限制日志大小
[root@test ~]# cat /etc/docker/daemon.json
{
"log-driver": "json-file",
"log-opts": {
"max-size": "500m",
"max-file": "3"
}
}
max-size=500m,代表一个容器日志大小上限是500M
max-file=3,代表一个容器有三个日志,分别是id+.json、id+1.json、id+2.json。
systemctl daemon-reload
systemctl restart docker