You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 22虚拟机构建Docker镜像遇Alpine源临时错误求助

解决Docker构建中Alpine v3.14源访问失败的问题

可行解决方法:

1. 替换Alpine镜像源

Alpine v3.14为停止维护的旧版本,官方CDN访问易不稳定,可更换为国内镜像源。修改Dockerfile,在apk update前添加换源命令:

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
    apk update && apk add git unzip luarocks

2. 排查虚拟机网络连通性

  • 在Ubuntu虚拟机中执行curl -I https://dl-cdn.alpinelinux.org/alpine/v3.14/main/APKINDEX.tar.gz,验证是否能正常访问源地址
  • 若无法访问,检查虚拟机DNS配置,尝试更换为8.8.8.8或国内公共DNS

3. 清理Docker构建缓存

缓存可能留存错误的源状态,清理后重新构建:

docker builder prune -a
docker build .

4. 升级基础镜像版本

Kong 2.7.0基于已停止维护的Alpine 3.14,建议升级到kong/kong:3.x系列版本,其依赖的Alpine版本更稳定,源访问问题更少


原问题详情:

在Ubuntu 22虚拟机中构建Docker镜像时,执行docker build命令的RUN apk update && apk add git unzip luarocks步骤报错,提示Alpine Linux v3.14的main和community源出现临时错误。Docker版本为20.10.18,build b40c2f6,已尝试重启Docker引擎未解决。

构建日志:

[+] Building 10.6s (5/14)                                                                                                                        
 => [internal] load build definition from Dockerfile                                                                                        0.0s
 => => transferring dockerfile: 864B                                                                                                        0.0s
 => [internal] load .dockerignore                                                                                                           0.0s
 => => transferring context: 2B                                                                                                             0.0s
 => [internal] load metadata for docker.io/kong/kong:2.7.0                                                                                  0.0s
 => CACHED [ 1/12] FROM docker.io/kong/kong:2.7.0                                                                                           0.0s
 => ERROR [ 2/12] RUN apk update && apk add git unzip luarocks                                                                             10.5s
------                                                                                                                                           
 > [ 2/12] RUN apk update && apk add git unzip luarocks:                                                                                         
#0 0.240 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz                                                           
#0 5.245 ERROR: https://dl-cdn.alpinelinux.org/alpine/v3.14/main: temporary error (try again later)                                              
#0 5.283 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/x86_64/APKINDEX.tar.gz                                                      
#0 10.29 ERROR: https://dl-cdn.alpinelinux.org/alpine/v3.14/community: temporary error (try again later)                                         
#0 10.48 v3.14.3-58-g7fc21b9dfb [https://dl-cdn.alpinelinux.org/alpine/v3.14/main]
#0 10.48 v3.14.3-57-g005638434d [https://dl-cdn.alpinelinux.org/alpine/v3.14/community]
#0 10.48 2 errors; 14942 distinct packages available
------
failed to solve: executor failed running [/bin/sh -c apk update && apk add git unzip luarocks]: exit code: 2

Docker版本信息:

Docker version 20.10.18, build b40c2f6

已尝试操作:

  • 重启Docker引擎

内容的提问来源于stack exchange,提问作者scripter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 05:55:24