docker資源清理

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

查看某個容器占用磁盤特別大

  1. 查看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
  1. 修改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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容