# Harbor教程 - 遇到的错误
# 1 Dockerfile使用私有镜像报错
在安装 Harbor 的时候,使用的是 http 协议,例如:http://harbor.doubibiji.com
并上传了一个镜像为: harbor.doubibiji.com/images/test:1.0.0
。
但是编排 Dockerfile 的时候,基于这个私有镜像构建其他镜像会报错:
FROM harbor.doubibiji.com/images/test:1.0.0
报错:
ERROR: failed to solve: DeadlineExceeded: DeadlineExceeded: DeadlineExceeded: harbor.doubibiji.com/images/test:1.0.0: failed to resolve source metadata for harbor.doubibiji.com/images/test:1.0.0: failed to do request: Head "https://harbor.doubibiji.com/v2/images/test/manifests/1.0.0": dial tcp xxx.xxx.xxx.xxx:443: i/o timeout
依然找的是https协议
1
2
3
4
5
2
3
4
5
但是我的机器上已经在文件 /etc/docker/daemon.json
中配置了:
{
"insecure-registries": [
"harbor.doubibiji.com"
]
}
1
2
3
4
5
2
3
4
5
而且通过 docker pull harbor.doubibiji.com/images/test:1.0.0
也是可以成功的,如果将这个镜像拉取到本地,在基于这个镜像构建其他镜像,就又没有问题。
我找到了一个解释:
Docker在v23.0版本及以后,使用了新的构建工具 BuildKit ,目前 BuildKit 对 insecure-registries 配置可能没做兼容,构建Dockerfile FROM镜像时未判断是私库,导致报错。
处理方式:
添加环境变量,在 ~/.bashrc
或 /etc/profile
添加一行 export DOCKER_BUILDKIT=0
,然后 source
一个修改的配置文件。
echo "export DOCKER_BUILDKIT=0" >> ~/.bashrc
source ~/.bashrc
1
2
2
通过配置环境变量,禁用 BuildKit,使用传统的 Docker 构建工具。
要么就先用 docker pull
命令,将 FROM
用到的镜像拉取到本地,在执行 docker build
。