各位,这个 glibc 的版本是 2.35-r1 , 可否有更优雅高级点写法,能下载总是 latest 版本 glibc,这样就节约了维护 dockerfile 文件的时间和精力?
RUN curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r1/glibc-2.35-r1.apk
&& curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r1/glibc-bin-2.35-r1.apk
&& curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r1/glibc-dev-2.35-r1.apk
&& curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r1/glibc-i18n-2.35-r1.apk
RUN apk add --force-overwrite glibc-2.35-r1.apk
&& rm glibc-2.35-r1.apk
&& apk add --force-overwrite glibc-bin-2.35-r1.apk
&& rm glibc-bin-2.35-r1.apk
&& apk add --force-overwrite glibc-dev-2.35-r1.apk
&& rm glibc-dev-2.35-r1.apk
&& apk add --force-overwrite glibc-i18n-2.35-r1.apk
&& rm glibc-i18n-2.35-r1.apk
目前写法:
RUN curl -L -o /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
&& curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r1/glibc-2.35-r1.apk
&& curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r1/glibc-bin-2.35-r1.apk
&& curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r1/glibc-dev-2.35-r1.apk
&& curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r1/glibc-i18n-2.35-r1.apk
RUN apk add --force-overwrite glibc-2.35-r1.apk
&& rm glibc-2.35-r1.apk
&& apk add --force-overwrite glibc-bin-2.35-r1.apk
&& rm glibc-bin-2.35-r1.apk
&& apk add --force-overwrite glibc-dev-2.35-r1.apk
&& rm glibc-dev-2.35-r1.apk
&& apk add --force-overwrite glibc-i18n-2.35-r1.apk
&& rm glibc-i18n-2.35-r1.apk
我打算参考下面这段来写,但是没成功
····
RUN DOWNLOAD_URL=$(curl -s "https://api.github.com/repos/invoiceninja/invoiceninja/releases/latest" | grep -o '"browser_download_url": "[^"]*invoiceninja.tar"' | cut -d '"' -f 4) &&
curl -LJO "$DOWNLOAD_URL" &&
mv invoiceninja.tar /tmp/ninja.tar
RUN mkdir -p /var/www/app
&& tar -xvf /tmp/ninja.tar -C /var/www/app/
&& mkdir -p /var/www/app/public/logo /var/www/app/storage
····
1
DsuineGP 142 天前 1
version = $(curl -s -L -I https://github.com/sgerrand/alpine-pkg-glibc/releases/latest | grep -i 'Location:' | awk -F '/' '{print $NF}')
curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/$(version)/$(version).apk |
2
KINGWAY OP @DsuineGP #1
那么这段呢? RUN apk add --force-overwrite glibc-2.35-r1.apk && rm glibc-2.35-r1.apk && apk add --force-overwrite glibc-bin-2.35-r1.apk && rm glibc-bin-2.35-r1.apk && apk add --force-overwrite glibc-dev-2.35-r1.apk && rm glibc-dev-2.35-r1.apk && apk add --force-overwrite glibc-i18n-2.35-r1.apk && rm glibc-i18n-2.35-r1.apk |
3
victor 142 天前 1
# 获取 glibc 的最新版本号
RUN LATEST_VERSION=$(curl -s https://api.github.com/repos/sgerrand/alpine-pkg-glibc/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")') && \ curl -L -o /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \ curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${LATEST_VERSION}/glibc-${LATEST_VERSION}.apk && \ curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${LATEST_VERSION}/glibc-bin-${LATEST_VERSION}.apk && \ curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${LATEST_VERSION}/glibc-dev-${LATEST_VERSION}.apk && \ curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${LATEST_VERSION}/glibc-i18n-${LATEST_VERSION}.apk && \ apk add --force-overwrite glibc-${LATEST_VERSION}.apk && \ rm glibc-${LATEST_VERSION}.apk && \ apk add --force-overwrite glibc-bin-${LATEST_VERSION}.apk && \ rm glibc-bin-${LATEST_VERSION}.apk && \ apk add --force-overwrite glibc-dev-${LATEST_VERSION}.apk && \ rm glibc-dev-${LATEST_VERSION}.apk && \ apk add --force-overwrite glibc-i18n-${LATEST_VERSION}.apk && \ rm glibc-i18n-${LATEST_VERSION}.apk |
4
KINGWAY OP @victor 跑了下没有成功,出错信息如下:
106 | 107 | >>> RUN LATEST_VERSION=$(curl -s https://api.github.com/repos/sgerrand/alpine-pkg-glibc/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")') && \ 108 | >>> curl -L -o /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \ 109 | >>> curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${LATEST_VERSION}/glibc-${LATEST_VERSION}.apk && \ 110 | >>> curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${LATEST_VERSION}/glibc-bin-${LATEST_VERSION}.apk && \ 111 | >>> curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${LATEST_VERSION}/glibc-dev-${LATEST_VERSION}.apk && \ 112 | >>> curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${LATEST_VERSION}/glibc-i18n-${LATEST_VERSION}.apk && \ 113 | >>> apk add --force-overwrite glibc-${LATEST_VERSION}.apk && \ 114 | >>> rm glibc-${LATEST_VERSION}.apk && \ 115 | >>> apk add --force-overwrite glibc-bin-${LATEST_VERSION}.apk && \ 116 | >>> rm glibc-bin-${LATEST_VERSION}.apk && \ 117 | >>> apk add --force-overwrite glibc-dev-${LATEST_VERSION}.apk && \ 118 | >>> rm glibc-dev-${LATEST_VERSION}.apk && \ 119 | >>> apk add --force-overwrite glibc-i18n-${LATEST_VERSION}.apk && \ 120 | >>> rm glibc-i18n-${LATEST_VERSION}.apk 121 | -------------------- ERROR: failed to solve: process "/bin/sh -c LATEST_VERSION=$(curl -s https://api.github.com/repos/sgerrand/alpine-pkg-glibc/releases/latest | grep -oP '\"tag_name\": \"\\K(.*)(?=\")') && curl -L -o /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${LATEST_VERSION}/glibc-${LATEST_VERSION}.apk && curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${LATEST_VERSION}/glibc-bin-${LATEST_VERSION}.apk && curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${LATEST_VERSION}/glibc-dev-${LATEST_VERSION}.apk && curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${LATEST_VERSION}/glibc-i18n-${LATEST_VERSION}.apk && apk add --force-overwrite glibc-${LATEST_VERSION}.apk && rm glibc-${LATEST_VERSION}.apk && apk add --force-overwrite glibc-bin-${LATEST_VERSION}.apk && rm glibc-bin-${LATEST_VERSION}.apk && apk add --force-overwrite glibc-dev-${LATEST_VERSION}.apk && rm glibc-dev-${LATEST_VERSION}.apk && apk add --force-overwrite glibc-i18n-${LATEST_VERSION}.apk && rm glibc-i18n-${LATEST_VERSION}.apk" did not complete successfully: exit code: 2 |
5
victor 142 天前
FROM alpine:latest
# 添加 sgerrand 的公钥 RUN curl -L -o /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub # 获取 glibc 的最新版本号并下载相关文件 RUN LATEST_VERSION=$(curl -s https://api.github.com/repos/sgerrand/alpine-pkg-glibc/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")') && \ echo "Latest version is $LATEST_VERSION" && \ curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${LATEST_VERSION}/glibc-${LATEST_VERSION}.apk && \ curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${LATEST_VERSION}/glibc-bin-${LATEST_VERSION}.apk && \ curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${LATEST_VERSION}/glibc-dev-${LATEST_VERSION}.apk && \ curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${LATEST_VERSION}/glibc-i18n-${LATEST_VERSION}.apk # 安装 glibc 相关包并清理 RUN apk add --force-overwrite glibc-*.apk && \ rm glibc-*.apk # 运行时所需配置 RUN /usr/glibc-compat/bin/localedef -i en_US -f UTF-8 en_US.UTF-8 || true # 设置环境变量 ENV LD_LIBRARY_PATH=/usr/glibc-compat/lib ENV LANG=en_US.UTF-8 |
6
victor 142 天前
你跟 gpt 对话能更快的到答案,比这里问方便多了
|
7
Mikex88 142 天前
单个执行有利于 docker build 缓存吧?
|
8
sunny352787 142 天前
@KINGWAY 好家伙,你跟这 GPT 呢?
|
9
KINGWAY OP chatgpt 上拿到的很多通不过实际编译啊, 就比如你最后这段一样失败了。
|
10
wonderfulcxm 142 天前 via iPhone
@sunny352787 哈哈,确实像我跟 gpt 的对话
|
11
KINGWAY OP @wonderfulcxm : )
其实也还好啦,最起码下面这段我用上了 # 安装 glibc 相关包并清理 RUN apk add --force-overwrite glibc-*.apk && \ rm glibc-*.apk |
12
artiga033 141 天前
说到底这并不是一个 docker 问题而是一个 shell script 问题
```sh curl 'https://api.github.com/repos/sgerrand/alpine-pkg-glibc/releases/latest' | sed -rn 's/^.*browser_download_url.*( https:.*\.apk).*$/\1/p' | xargs -n 1 curl -LO ``` |
13
KINGWAY OP @artiga033 你这个无效, 不过可以编译下去,估计稍微排查就可以了。
curl 'https://api.github.com/repos/sgerrand/alpine-pkg-glibc/releases/latest' | sed -rn 's/^.*browser_download_url.*( https:.*\.apk).*$/\1/p' | xargs -n 1 curl -LO % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 10603 0 10603 0 0 69205 0 --:--:-- --:--:-- --:--:-- 69756 curl: no URL specified! curl: try 'curl --help' or 'curl --manual' for more information |
14
ko20 141 天前
这种 bash/shell 问题,问 gpt 很快的,不过可能需要你来回调试两三次,就 ok 了。问得具体一点,能得到更准确的回答
|
15
KINGWAY OP @ko20 是的,修改为
RUN curl -s 'https://api.github.com/repos/sgerrand/alpine-pkg-glibc/releases/latest' | grep 'browser_download_url' | sed -E 's/.*"([^"]+)".*/\1/' | xargs -n 1 curl -LO 就没问题了,几个文件也都拉下来了 |
16
anubu 141 天前
2 个 RUN 就是 2 层了,后面的 rm 应该没有精简镜像的效果了。常规实践中下载并清理的场景应该放在同一层。
|
17
KINGWAY OP @anubu 其实还行,我跑了下编译没问题, 也可以拉起来, 准备提交 PR
https://github.com/Kingwayer/dockerfiles/blob/master/alpine/5/Dockerfile |