ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

docker 磁盘空间、日志、Volume清理

2021-05-24 12:51:33  阅读:154  来源: 互联网

标签:-- Volume 磁盘空间 ------. ls docker drwx root


下面是记录一下docker 涉及磁盘空间时会用上的命令,
docker system 是1.13及之后的版本才有的。

一、镜像
# 查看当前docker使用的磁盘情况
[root@C7-slave-72 ~]# docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          0         0         0B        0B
Containers      17        0         2.45kB    2.45kB (100%)
Local Volumes   0         0         0B        0B
Build Cache     0         0         0B        0B

# 查看当前docker image
[root@C7-slave-72 ~]# docker image ls
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

# 查看prune命令作用用法
[root@C7-slave-72 ~]# docker system prune --help

Usage:  docker system prune [OPTIONS]

Remove unused data

Options:
  -a, --all             Remove all unused images not just dangling ones
      --filter filter   Provide filter values (e.g. 'label=<key>=<value>')
  -f, --force           Do not prompt for confirmation
      --volumes         Prune volumes

#默认会清除"悬空"镜像【就是既没有标签名也没有容器引用的镜像】--- dangling镜像
[root@C7-slave-72 ~]# 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] y

# 删除所有 没正在使用的 镜像、容器、存储卷、网络
docker system prune -a
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all images without at least one container associated to them
  - all build cache

Are you sure you want to continue? [y /N]

# 强制删除,不需要进行交互式确认
docker system prune -f

# 手工删除特定的镜像
docker rmi <镜像名>

二、日志
容器日志一般存放在/var/lib/docker下面
[root@C7-slave-72 ~]# ll -h /var/lib/docker
total 16K
drwx------.  2 root root   24 Oct 23  2018 builder
drwx------.  4 root root  139 Apr 18 16:49 buildkit
drwx------.  3 root root   20 Oct 23  2018 containerd
drwx-----x. 19 root root 4.0K May  4 06:27 containers
drwx------.  3 root root   22 Oct 23  2018 image
drwxr-x---.  3 root root   19 Oct 23  2018 network
drwx-----x. 58 root root 8.0K May 24 19:41 overlay2
drwx------.  4 root root   32 Oct 23  2018 plugins
drwx------.  2 root root    6 May 24 19:41 runtimes
drwx------.  2 root root    6 Oct 23  2018 swarm
drwx------.  2 root root    6 May 24 19:41 tmp
drwx------.  2 root root    6 Oct 23  2018 trust
drwx-----x.  2 root root   50 May 24 19:41 volumes

# 查看容器的日志
ls -lh $(find /var/lib/docker/containers/ -name *-json.log)

三、手工删除储存卷
# 查看volume
docker volume ls

# 删除所有dangling数据卷(即无用的Volume)
docker volume rm $(docker volume ls -qf dangling=true)

# volume ls 命令帮助
[root@lab73 ~]# docker volume ls --help

Usage:  docker volume ls [OPTIONS]

List volumes

Aliases:
  ls, list

Options:
  -f, --filter filter   Provide filter values (e.g. 'dangling=true')
      --format string   Pretty-print volumes using a Go template
  -q, --quiet           Only display volume names

标签:--,Volume,磁盘空间,------.,ls,docker,drwx,root
来源: https://blog.51cto.com/jackor/2806822

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有