docker build 构建时 alpinelinux 镜像权限错误

问题

使用 docker build 构建镜像时,发生一个错误:“ERROR: https://dl-cdn.alpinelinux.org/alpine/v3.15/main: Permission denied”。部分日志如下:

[2023-03-30 14:51:12] Step 3/16 : RUN apk update && apk upgrade && apk add musl-dev make gcc python3
[2023-03-30 14:51:12]  ---> Running in 47ef30b3d669
[2023-03-30 14:51:13] fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
[2023-03-30 14:51:13] ERROR: https://dl-cdn.alpinelinux.org/alpine/v3.15/main: Permission denied
[2023-03-30 14:51:13] WARNING: Ignoring https://dl-cdn.alpinelinux.org/alpine/v3.15/main: No such file or directory
[2023-03-30 14:51:13] fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
[2023-03-30 14:52:21] v3.15.7-84-g97bd2f633e0 [https://dl-cdn.alpinelinux.org/alpine/v3.15/community]
[2023-03-30 14:52:21] 1 errors; 11050 distinct packages available
[2023-03-30 14:52:21] The command '/bin/sh -c apk update && apk upgrade && apk add musl-dev make gcc python3' returned a non-zero code: 1

原因

There has been multiple issues with libfetch and proxy + https.

借用 https://github.com/alpinelinux/docker-alpine/issues/98#issuecomment-763055441 的话,应该是使用过程中 libfetch 的问题。

解决方案:

Dockerfile 中增加一行:

RUN sed -i 's/https/http/' /etc/apk/repositories

参考


image

posted @ 2023-03-30 20:00  暮重云  阅读(2520)  评论(0编辑  收藏  举报