问题描述
环境: Ubuntn 18.04
Docker 版本: Docker version 23.0.1, build a5ee5b1
Dockerfile:
FROM alpine
#将国外镜像地址替换为阿里云镜像的地址
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
RUN apk update
COPY start.sh /usr/bin/
RUN chmod 755 /usr/bin/start.sh
ENTRYPOINT (sh /usr/bin/start.sh)
报错描述:temporary error
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 406B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/alpine:latest 1.6s
=> [1/8] FROM docker.io/library/alpine@sha256:69665d02cb32192e52e07644d76bc6f25abeb5410edc1c7a81a10ba3f0efb90a 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 138B 0.0s
=> CACHED [2/8] RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories 0.0s
=> ERROR [3/8] RUN apk update 10.6s
------
> [3/8] RUN apk update:
#0 0.461 fetch https://mirrors.aliyun.com/alpine/v3.17/main/x86_64/APKINDEX.tar.gz
#0 5.468 ERROR: https://mirrors.aliyun.com/alpine/v3.17/main: temporary error (try again later)
#0 5.468 WARNING: Ignoring https://mirrors.aliyun.com/alpine/v3.17/main: No such file or directory
#0 5.469 fetch https://mirrors.aliyun.com/alpine/v3.17/community/x86_64/APKINDEX.tar.gz
#0 10.47 ERROR: https://mirrors.aliyun.com/alpine/v3.17/community: temporary error (try again later)
#0 10.47 WARNING: Ignoring https://mirrors.aliyun.com/alpine/v3.17/community: No such file or directory
#0 10.47 2 errors; 15 distinct packages available
------
Dockerfile:4
--------------------
2 |
3 | RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
4 | >>> RUN apk update
--------------------
ERROR: failed to solve: process "/bin/sh -c apk update" did not complete successfully: exit code: 2
镜像地址已经替换为阿里云镜像的地址了,并且在Ubuntn 上用 wget 也能下载 https://mirrors.aliyun.com/alpine/v3.17/main/x86_64/APKINDEX.tar.gz,但使用 "docker build myproject:v1 . " 命令构建对象,依然还是报这个错误。
解决方法
给docker配置DNS解析服务器:
配置文件的路径: /etc/docker/daemon.json,没有此配置文件的话就新建一个
补充完整dns配置内容:
{
"registry-mirror":[
""
],
"dns":[
"114.114.114.114",
"8.8.8.8"
]
}
重启docker:
systemctl restart docker