1、镜像拉取失败
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| # 检查镜像拉取错误 docker pull <镜像名> -a # 拉取所有标签 # 查看Docker镜像仓库配置 docker info | grep "Registry Mirrors:" -A 10 # 测试仓库连接 curl -v https://registry-1.docker.io/v2/ # 更换镜像源 修改 /etc/docker/daemon.json { ...... "registry-mirrors": ["https://mirror.example.com"], ...... } systemctl daemon-reload systemctl restart docker # 手动下载并导入镜像 docker save -o <镜像名>.tar <镜像名> # 从其他机器导出 scp <镜像名>.tar <目标机器>:~ docker load -i <镜像名>.tar |
2、Dockerfile 构建错误
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| # 详细构建并显示每一步 docker build -t <镜像名> . --progress=plain --no-cache # 定位具体失败的构建步骤 docker build --target=<阶段名> -t <临时镜像名> . # 检查基础镜像可用性 docker pull <基础镜像名> # 资源限制导致的构建失败(增加内存/CPU) docker build -t <镜像名> . --memory=4g --cpus=2 # 查看构建缓存使用情况 docker system df -v | grep <镜像名> |
3、镜像损坏或校验失败
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| # 检查镜像完整性 docker images --digests docker inspect --format '{{.RepoDigests}}' <镜像名> # 清理损坏的镜像 docker rmi -f <镜像ID> # 强制清理 docker image prune -f # 重新拉取镜像 docker pull <镜像名> # 手动验证镜像校验和 curl -sL https://registry.hub.docker.com/v2/\<镜像路径>/manifests/<标签> | jq '.config.digest' |