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

下面是记录一下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
上一篇:docker的存储目录迁移


下一篇:微信中无法下载APP的解决方案(微信自动跳转浏览器打开下载链接)