1. Buid cache 简介
    平常我们会在docker 构建环境下不断地构建新的镜像,但是当我们不断地构建新的镜像的时候总是获取不到我们需要的镜像,为什么会这个样子呢?其实,是由于image cache 导致的,本身cache 是为了提升build 速度,其会利用现有的cache 来快速构建新的image,因此,当我们构建 image 有问题可以尝试清理下本地的cache;

  2. 清理本地cache

# docker system prune --volumes
WARNING! This will remove:
  - all stopped containers  # 释放所有stop 的容器
  - all networks not used by at least one container
  - all volumes not used by at least one container
  - all dangling images # 所有虚悬镜像(dangling image)
  - all dangling build cache # 虚悬镜像(dangling image)缓存

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

# docker system prune --all  清除所有缓存
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]
  1. 一键清除本地缓存的所有无用的docker镜像命令:
    docker images -q --filter "dangling=true" | xargs -t --no-run-if-empty docker rmi