记录下amd64平台下,Docker 构建多环境平台报错后的解决方法。
我自己的电脑系统是X86_64(amd64)平台,想构建多环境平台的镜像,并推送镜像到Harbar,在执行命令
docker buildx build --platform linux/amd64,linux/arm64 -f ./Dockerfile -t "harbor.xxxx.net/ailp/ee/frontend/app:v3.0.3.9" .
时报错如下:
=> ERROR [internal] booting buildkit 15.3s
=> => pulling image moby/buildkit:buildx-stable-1 15.3s
------
> [internal] booting buildkit:
------
WARNING: No output specified with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
ERROR: failed to build: Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
报错上说有两个问题:
- 网络连接问题,意思就是镜像源需要配置国内镜像加速器
- 构建命令中没有指定输出方式,意思就是需要在命令行后增加–push
针对报错问题进行解决:
步骤一:打开Docker Desktop小鲸鱼图标应用,在设置中找到Docker Engine中配置镜像源,然后重启Docker Desktop应用,点击左下角,切换状态,点击Restart,重新启动服务。注意一定要重新启动配置的镜像源才会生效
"registry-mirrors": [
"https://docker.m.daocloud.io/",
"https://huecker.io/",
"https://dockerhub.timeweb.cloud",
"https://noohub.ru/",
"https://dockerproxy.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.nju.edu.cn",
"https://xx4bwyg2.mirror.aliyuncs.com",
"http://f1361db2.m.daocloud.io",
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"
]
想要验证镜像源是否配置成功,可打开终端,输入命令 docker info ,如果Registry Mirrors下能输出刚配置的镜像源,则镜像源配置成功
docker info
正常输出如下:
Client:
Version: 28.3.2
Context: desktop-linux
Debug Mode: false
Plugins:
ai: Docker AI Agent - Ask Gordon (Docker Inc.)
Version: v1.9.11
Path: C:\Users\shiqiaoyun\.docker\cli-plugins\docker-ai.exe
buildx: Docker Buildx (Docker Inc.)
Version: v0.26.1-desktop.1
Path: C:\Users\shiqiaoyun\.docker\cli-plugins\docker-buildx.exe
cloud: Docker Cloud (Docker Inc.)
Version: v0.4.11
Path: C:\Users\shiqiaoyun\.docker\cli-plugins\docker-cloud.exe
compose: Docker Compose (Docker Inc.)
Version: v2.39.1-desktop.1
Path: C:\Users\shiqiaoyun\.docker\cli-plugins\docker-compose.exe
debug: Get a shell into any image or container (Docker Inc.)
Version: 0.0.42
Path: C:\Users\shiqiaoyun\.docker\cli-plugins\docker-debug.exe
desktop: Docker Desktop commands (Docker Inc.)
Version: v0.2.0
Path: C:\Users\shiqiaoyun\.docker\cli-plugins\docker-desktop.exe
extension: Manages Docker extensions (Docker Inc.)
Version: v0.2.29
Path: C:\Users\shiqiaoyun\.docker\cli-plugins\docker-extension.exe
init: Creates Docker-related starter files for your project (Docker Inc.)
Version: v1.4.0
Path: C:\Users\shiqiaoyun\.docker\cli-plugins\docker-init.exe
mcp: Docker MCP Plugin (Docker Inc.)
Version: v0.13.0
Path: C:\Users\shiqiaoyun\.docker\cli-plugins\docker-mcp.exe
model: Docker Model Runner (EXPERIMENTAL) (Docker Inc.)
Version: v0.1.36
Path: C:\Users\shiqiaoyun\.docker\cli-plugins\docker-model.exe
sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
Version: 0.6.0
Path: C:\Users\shiqiaoyun\.docker\cli-plugins\docker-sbom.exe
scout: Docker Scout (Docker Inc.)
Version: v1.18.2
Path: C:\Users\shiqiaoyun\.docker\cli-plugins\docker-scout.exe
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 1
Server Version: 28.3.2
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
CDI spec directories:
/etc/cdi
/var/run/cdi
Discovered Devices:
cdi: docker.com/gpu=webgpu
Swarm: inactive
Runtimes: io.containerd.runc.v2 nvidia runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 05044ec0a9a75232cad458027ca83437aae3f4da
runc version: v1.2.5-0-g59923ef
init version: de40ad0
Security Options:
seccomp
Profile: builtin
cgroupns
Kernel Version: 6.6.87.2-microsoft-standard-WSL2
Operating System: Docker Desktop
OSType: linux
Architecture: x86_64
CPUs: 12
Total Memory: 7.62GiB
Name: docker-desktop
ID: a08de987-7756-4e24-bf3e-ad7df58ac2fc
Docker Root Dir: /var/lib/docker
Debug Mode: false
HTTP Proxy: http.docker.internal:3128
HTTPS Proxy: http.docker.internal:3128
No Proxy: hubproxy.docker.internal
Labels:
com.docker.desktop.address=npipe://\\.\pipe\docker_cli
Experimental: true
Insecure Registries:
harbor.xxxx.net
hubproxy.docker.internal:5555
::1/128
127.0.0.0/8
Registry Mirrors:
https://docker.m.daocloud.io/
https://huecker.io/
https://dockerhub.timeweb.cloud/
https://noohub.ru/
https://dockerproxy.com/
https://docker.mirrors.ustc.edu.cn/
https://docker.nju.edu.cn/
https://xx4bwyg2.mirror.aliyuncs.com/
http://f1361db2.m.daocloud.io/
https://registry.docker-cn.com/
http://hub-mirror.c.163.com/
Live Restore Enabled: false
WARNING: DOCKER_INSECURE_NO_IPTABLES_RAW is set
步骤二:在构建命令后增加–push,指定输出方式
docker buildx build --platform linux/amd64,linux/arm64 -f ./Dockerfile -t "harbor.xxxx.net/ailp/ee/frontend/app:v3.0.3.9" --push .
正确输出如下,则构建成功
```javascript
[+] Building 7.2s (11/11) FINISHED docker-container:multi-platform-builder
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 184B 0.0s
=> [linux/arm64 internal] load metadata for harbor.xxxx.net/ailp/ee/frontend/base:v2 0.3s
=> [linux/amd64 internal] load metadata for harbor.xxxx.net/ailp/ee/frontend/base:v2 0.3s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 142B 0.0s
=> [linux/arm64 1/2] FROM harbor.xxxx.net/ailp/ee/frontend/base:v2@sha256:6ad3d6ed02c959a331f7b4ae644829af9a255 0.0s
=> => resolve harbor.xxxx.net/ailp/ee/frontend/base:v2@sha256:6ad3d6ed02c959a331f7b4ae644829af9a255d8c95ffc47b4 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 132.21kB 0.1s
=> [linux/amd64 1/2] FROM harbor.xxxx.net/ailp/ee/frontend/base:v2@sha256:6ad3d6ed02c959a331f7b4ae644829af9a255 0.0s
=> => resolve harbor.xxxx.net/ailp/ee/frontend/base:v2@sha256:6ad3d6ed02c959a331f7b4ae644829af9a255d8c95ffc47b4 0.0s
=> CACHED [linux/amd64 2/2] COPY dist /usr/share/nginx/html 0.0s
=> CACHED [linux/arm64 2/2] COPY dist /usr/share/nginx/html 0.0s
=> exporting to image 6.6s
=> => exporting layers 3.4s
=> => exporting manifest sha256:62869d8fc9b0ac0d0f7264f9908df7913c5a044447f09eb6ed55912e148dfef4 0.0s
=> => exporting config sha256:e22509d4a4d5492e171e8c64682294d6f365d6c93da8339dfdfcb2ac5c1788cc 0.0s
=> => exporting attestation manifest sha256:ae5a3b66a0ea671f389301130a333db68b82aa606587b497faf8216698b4e640 0.0s
=> => exporting manifest sha256:68eafff9180ad6ca5b90baf644bf82d0f92ac308ede3db6904b1ddd4e9a7ccce 0.0s
=> => exporting config sha256:7e9ee34b58434675a6006d34fcc194a1cab3bf5d8addc64dad25a3beb1887c36 0.0s
=> => exporting attestation manifest sha256:cf8f688899e2b5e12007bb537e99ff1b39e50a4d4de05a08f5385061bc027c20 0.1s
=> => exporting manifest list sha256:1a706ff8a56c57f545bd10807c55750b86a4b03ae2870d3b3f87992ac87450a0 0.0s
=> => pushing layers 2.0s
=> => pushing manifest for harbor.xxxx.net/ailp/ee/frontend/app:v3.0.3.9@sha256:1a706ff8a56c57f545bd10807c55750 0.9s
=> [auth] ailp/ee/frontend/app:pull,push token for harbor.xxxx.net 0.0s
View build details: docker-desktop://dashboard/build/multi-platform-builder/multi-platform-builder0/liuedj57irmckc7smjurv8sfm