如何从 dockerfile 中的在线文件读取和使用 url

How can I read and use url from an online file in dockerfile

我正在尝试创建一个 Dockerfile 从在线文件中读取一些 URL,但是当我尝试将 wget 与 URL 一起使用时变量,它失败了。如果我在控制台消息中打印变量,结果是正确的 URLs.

如果变量是用 ENV 声明的或用 URL 初始化的,我在 wget 中使用它没有问题;该问题仅在从文件读取 URL 时发生。

FROM openjdk:8

USER root
RUN mkdir /opt/tools /aplicaciones /deployments \
    && wget -q "www.url_online_file.com" -O url.txt \
    && while IFS== read -r name url; do if [ $name = "url1" ]; then export URL1=$url; fi; if [ $name = "url2" ]; then export URL2=$url; fi; done < url.txt \
    && echo "DEBUG URL1=$URL1"; echo "DEBUG URL2=$URL2"; \
    && wget -q $URL1 -O url1.zip

错误:

DEBUG URL1=www.prueba1.com
DEBUG URL2=www.prueba2.com
The command '/bin/sh -c mkdir /opt/tools /aplicaciones /deployments     && wget -q "www.url_online_file.com" -O url.txt     && while IFS== read -r name url; do if [ $name = "url1" ]; then export URL1=$url; fi; if [ $name = "url2" ]; then export URL2=$url; fi; done < url.txt  && echo "DEBUG URL1=$URL1"; echo "DEBUG URL2=$URL2";     && wget -q $URL1 -O url1.zip' returned a non-zero code: 8

online_file中的file.txt结构是:

url1=www.prueba1.com
url2=www.prueba2.com

解决方案是对www.url_online_file.com使用命令wget -i并将文件内容修改为:

www.prueba1.com
www.prueba2.com

dockerfile:

FROM openjdk:8

USER root
RUN mkdir /opt/tools /aplicaciones /deployments \
    && wget -i "www.url_online_file.com" \
    && && rm url* \
    && mv url1* url1.zip \
    && mv url2* url2.zip \
    && unzip url1.zip -d /opt/tools \
    && unzip url2.zip -d /opt/tools \
    && rm url1.zip \
    && rm url2.zip