Docker 日志缓存过大清理方案(亲测)
docker磁盘不足异常现象记录
- docker磁盘不足异常现象记录
- 排查并定位问题
- 解决方案
- 参考地址
docker-compose INTERNAL ERROR: cannot create temporary directory!
排查并定位问题1
# 查看磁盘占用情况
[root@iZ25bmxsqmeZ ~]# df -h
2、查看docker 信息:docker info
# 查看基本信息
# 硬件驱动使用的是devicemapper,空间池为docker-252
# 磁盘可用容量仅剩16.78MB,可用供我们使用
$ docker info
Containers: 1
Images: 28
Storage Driver: devicemapper
Pool Name: docker-252:1-787932-pool
Pool Blocksize: 65.54 kB
Backing Filesystem: extfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 1.225 GB
Data Space Total: 107.4 GB
Data Space Available: 16.78 MB
Metadata Space Used: 2.073 MB
Metadata Space Total: 2.147 GB
3、显示哪些容器目录具有最大的日志文件 $ du -d1 -h /var/lib/docker/containers | sort -h
[root@iZ25bmxsqmeZ ~]# du -d1 -h /var/lib/docker/containers | sort -h
16G /var/lib/docker/containers/4a252a6b8860ab38870247d738722474a0eba6dd87a8f022991c744cac45c93b
14G /var/lib/docker/containers/f31fb5958c92205b5177ef08454b2d6b1b114e5b55046047998d0907ae475d2a
92K /var/lib/docker/containers/38737fb0c06ddd232da20e1780cb8c4b95001b608988ac1a805c542ace757d51
160K /var/lib/docker/containers/479ee3952916a521234b110fc7460a40b9f115ccdc8edb443d5caf181126083d
600K /var/lib/docker/containers/6b27ea2796fe030c7012d595c4e0eb2fe2992a0e54b12978cb2d5a71cc84e22f
48M /var/lib/docker/containers/171c8ff57d2bcb52cec8edba126b8533f3bc4eeedf0cf04fc4245fa6b46ca228
39G /var/lib/docker/containers
解决方案
清除您选择的容器日志文件的内容 $ cat /dev/null > /var/lib/docker/containers/container_id/container_log_name
[root@iZ25bmxsqmeZ ~]# cd /var/lib/docker/containers/171c8ff57d2bcb52cec8edba126b8533f3bc4eeedf0cf04fc4245fa6b46ca228
[root@iZ25bmxsqmeZ 171c8ff57d2bcb52cec8edba126b8533f3bc4eeedf0cf04fc4245fa6b46ca228]# ll
total 48344
-rw-r----- 1 root root 49472303 Oct 8 15:32 171c8ff57d2bcb52cec8edba126b8533f3bc4eeedf0cf04fc4245fa6b46ca228-json.log
-rw-rw-rw- 1 root root 3107 Oct 8 15:26 config.v2.json
-rw-r--r-- 1 root root 0 Oct 8 14:44 hash265704265
-rw-rw-rw- 1 root root 1158 Oct 8 15:26 hostconfig.json
-rw-r--r-- 1 root root 13 Oct 8 15:26 hostname
-rw-r--r-- 1 root root 176 Oct 8 15:26 hosts
-rw-r--r-- 1 root root 66 Oct 8 15:26 resolv.conf
-rw-r--r-- 1 root root 71 Oct 8 15:26 resolv.conf.hash
drwxrwxrwt 2 root root 40 Oct 8 15:26 shm
[root@iZ25bmxsqmeZ 171c8ff57d2bcb52cec8edba126b8533f3bc4eeedf0cf04fc4245fa6b46ca228]#
[root@iZ25bmxsqmeZ 171c8ff57d2bcb52cec8edba126b8533f3bc4eeedf0cf04fc4245fa6b46ca228]# cat /dev/null > 171c8ff57d2bcb52cec8edba126b8533f3bc4eeedf0cf04fc4245fa6b46ca228-json.log
[root@iZ25bmxsqmeZ 171c8ff57d2bcb52cec8edba126b8533f3bc4eeedf0cf04fc4245fa6b46ca228]# ll
total 24
-rw-r----- 1 root root 0 Oct 8 15:40 171c8ff57d2bcb52cec8edba126b8533f3bc4eeedf0cf04fc4245fa6b46ca228-json.log
-rw-rw-rw- 1 root root 3107 Oct 8 15:26 config.v2.json
-rw-r--r-- 1 root root 0 Oct 8 14:44 hash265704265
-rw-rw-rw- 1 root root 1158 Oct 8 15:26 hostconfig.json
-rw-r--r-- 1 root root 13 Oct 8 15:26 hostname
-rw-r--r-- 1 root root 176 Oct 8 15:26 hosts
-rw-r--r-- 1 root root 66 Oct 8 15:26 resolv.conf
-rw-r--r-- 1 root root 71 Oct 8 15:26 resolv.conf.hash
drwxrwxrwt 2 root root 40 Oct 8 15:26 shm
参考地址
https://blog.csdn.net/niu_hao/article/details/78873076 https://my.oschina.net/u/4350098/blog/4073527 https://zhuanlan.zhihu.com/p/377624621