我想从 Jenkins 服务器下载一个需要使用 Dockerfile 进行身份验证(用户名和密码)的文件
下面提供的是我的 Dockerfile 的前两行
FROM eclipse-temurin:17-alpine
RUN apk update && apk add --no-cache gcompat
然后我就有了
ENV REPO_USERNAME=test
ENV REPO_PASSWORD=testPassword
eclipse-temurin:17-alpine 包含 wget,所以我想我不需要另外安装它 ,所以我想解决方案会是这样的
RUN wget --user="$REPO_USERNAME" --password="$REPO_PASSWORD" -O reqLoader-linux http://10.80․10․2/tools/puppeteer-v13/reqLoader-linux
但是在运行 Dockerfile 时我收到此错误消息
#14 [10/14] RUN wget --user="test" --password="testPassword" -O reqLoader-linux http://10.80.10.2/tools/puppeteer-v13/reqLoader-linux
#14 0.272 wget: unrecognized option: password=testPassword
#14 0.275 BusyBox v1.36.1 (2023-07-27 17:12:24 UTC) multi-call binary.
#14 0.275
#14 0.275 Usage: wget [-cqS] [--spider] [-O FILE] [-o LOGFILE] [--header STR]
#14 0.275 [--post-data STR | --post-file FILE] [-Y on/off]
#14 0.275 [-P DIR] [-U AGENT] [-T SEC] URL...
#14 0.275
#14 0.275 Retrieve files via HTTP or FTP
#14 0.275
#14 0.275 --spider Only check URL existence: $? is 0 if exists
#14 0.275 --header STR Add STR (of form 'header: value') to headers
#14 0.275 --post-data STR Send STR using POST method
#14 0.275 --post-file FILE Send FILE using POST method
#14 0.275 -c Continue retrieval of aborted transfer
#14 0.275 -q Quiet
#14 0.275 -P DIR Save to DIR (default .)
#14 0.275 -S Show server response
#14 0.275 -T SEC Network read timeout is SEC seconds
#14 0.275 -O FILE Save to FILE ('-' for stdout)
#14 0.275 -o LOGFILE Log messages to FILE
#14 0.275 -U STR Use STR for User-Agent header
#14 0.275 -Y on/off Use proxy
#14 ERROR: process "/bin/sh -c wget --user=\"$REPO_USERNAME\" --password=\"$REPO_PASSWORD\" -O reqLoader-linux http://10.80․10․2/tools/puppeteer-v13/reqLoader-linux" did not complete successfully: exit code: 1
------
> [10/14] RUN wget --user="test" --password="testPassword" -O reqLoader-linux http://10.80․10․2/tools/puppeteer-v13/reqLoader-linux:
0.275 --post-file FILE Send FILE using POST method
0.275 -c Continue retrieval of aborted transfer
0.275 -q Quiet
0.275 -P DIR Save to DIR (default .)
0.275 -S Show server response
0.275 -T SEC Network read timeout is SEC seconds
0.275 -O FILE Save to FILE ('-' for stdout)
0.275 -o LOGFILE Log messages to FILE
0.275 -U STR Use STR for User-Agent header
0.275 -Y on/off Use proxy
------
Dockerfile:18
--------------------
16 |
17 | # Download reqLoader-linux and move it to the puppeteer directory
18 | >>> RUN wget --user="$REPO_USERNAME" --password="$REPO_PASSWORD" -O reqLoader-linux http://10.80․10․2/tools/puppeteer-v13/reqLoader-linux
我发现问题出在命令中提供用户名和密码,因为没有那种参数
详细信息 - 我正在 git bash(windows 11) 中使用 .sh 文件运行 Dockerfile
非常感谢有关如何使用 Dockerfile 从需要身份验证的远程服务器下载文件的任何其他建议
这样做的目的是让这些文件出现在图像中。
该错误是因为您使用的是wget,但Alpine Linux不直接支持“—user”和“—password”。 所以尝试使用curl,它看起来像这样:
FROM eclipse-temurin:17-alpine
RUN apk update && apk add --no-cache curl
ENV REPO_USERNAME=test
ENV REPO_PASSWORD=testPassword
RUN curl --user "$REPO_USERNAME:$REPO_PASSWORD" -o reqLoader-linux http://10.80.10.2/tools/puppeteer-v13/reqLoader-linux