【问题解决】docker版本v23.0后,构建Dockerfile中FROM私库镜像报错构建失败

问题情况

Docker版本在v23.0以后,只要Dockerfile中FROM的私库镜像不存在本地,就会报错:

# 我本地是v24.0.2版本Docker
[root@localhost ipd]# docker build . -t harbor.xxx.com.cn/test/bap:2.7.1
[+] Building 0.6s (3/3) FINISHED                                                                                                                                                                       docker:default
 => [internal] load build definition from Dockerfile                                                                                                                                                             0.2s
 => => transferring dockerfile: 1.05kB                                                                                                                                                                           0.0s
 => [internal] load .dockerignore                                                                                                                                                                                0.2s
 => => transferring context: 2B                                                                                                                                                                                  0.0s
 => ERROR [internal] load metadata for harbor.xxx.com.cn/xxx/tomcat:8.5.90-jdk8-temurin                                                                                                                      0.0s
------
 > [internal] load metadata for harbor.xxx.com.cn/xxx/tomcat:8.5.90-jdk8-temurin:
------
Dockerfile:2
--------------------
   1 |     #指定基础镜像
   2 | >>> FROM harbor.xxx.com.cn/xxx/tomcat:8.5.90-jdk8-temurin
   3 |     #指定环境变量,时区
   4 |     ENV TZ=Asia/Shanghai
--------------------
ERROR: failed to solve: harbor.xxx.com.cn/xxx/tomcat:8.5.90-jdk8-temurin: failed to do request: Head "https://harbor.xxx.com.cn/v2/xxx/tomcat/manifests/8.5.90-jdk8-temurin": tls: failed to verify certificate: x509: certificate signed by unknown authority

但我已经在 /etc/docker/daemon.json 中正确配置了 insecure-registries了,即能 pull 也能 push。

问题原因

Docker在v23.0版本及以后,使用了build-kit代替了旧的实现,目前build-kit对insecure-registries配置可能没做兼容,构建Dockerfile FROM镜像时未判断是私库,导致报错。

处理方式

目前(2023.07.21)办法就一个,在 ~/.bashrc/etc/profile 添加一行 export DOCKER_BUILDKIT=0,然后 source 一个修改的配置文件。

命令示例:

echo "export DOCKER_BUILDKIT=0" >> ~/.bashrc
source ~/.bashrc

后边如果有新的处理办法或者哪个版本解决这个问题,再来更贴。

本文引用:

  • https://github.com/docker/cli/blob/master/docs/deprecated.md#legacy-builder-fallback
  • https://github.com/docker/buildx/issues/1642
  • https://github.com/docker/buildx/issues/1687
  • https://github.com/docker/docs/pull/17746
  • https://github.com/moby/buildkit/pull/3382

你可能感兴趣的:(问题解决,#,Docker,docker,容器,运维)