平常我们会在docker 构建环境下不断地构建新的镜像,当不断地构建新的镜像的时候总是获取不到需要的镜像,是由于image cache 导致的,本身cache 是为了提升build 速度,其会利用现有的cache 来快速构建新的image,当我们构建 image 有问题可以尝试清理下本地的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]
ps
可以build 的时候加上--no-cache
无缓存build
docker-compose up --build -d
根据Dockerfile重新下载需要的镜像并构建容器,也就是说这句相当于是
docker-compose build --no-cache
和
docker-compose up -d
的集合体,意味着构建镜像的时候是根据Dockerfile的最新内容来的,而不会使用缓存,这样就避免了构建镜像时由于缓存造成的影响。