Dockerfile 脚本在本机 Ubuntu 中工作,但在 Windows 或 WSL 中不工作

Dockerfile script working in native Ubuntu but not in Windows or WSL

在我的 Dockerfile 中有下一个 运行 脚本:

RUN set -ex; \
  echo "Downloading plugins"; \
  cd /tmp/plugins; \
  for f in `cat plugins.list`; do\
    curl -O -fSL $f; \
  done;

当我从本机 Ubuntu 构建图像时,它可以完美运行,但是当我从 Powershell 或 Ubuntu 在 Windows 子系统 Linux 中构建图像时,它总是给出我同样的错误:

 ---> Running in 095faf998ee4
 + echo 'Downloading plugins'
 + cd /tmp/plugins
 Downloading plugins                                                                                             
 + cat plugins.list
 ' curl -O -fS 'https://downloads.wordpress.org/plugin/ninja-forms.3.4.19.zip
 curl: (3) URL using bad/illegal format or missing URL    

如果我 运行 直接从 bash 使用 curl 命令它也可以完美运行,但是如果我 运行 脚本的那部分它也会失败。

正如@cbley 评论的那样,问题出在 EOL 字符中,因为在 windows 上的默认 sublime 文本具有像 windows 这样的 EOL,它给脚本带来了错误。

要么像@cbley 对我的问题的评论那样用 tr -d '\r' < plugins.list > plugins.list_new 替换,要么通过将 "default_line_ending": "unix", 添加到 sublime 首选项来将 sublime text 的默认 EOL 设置为 "Unix" 就可以了。

谢谢@cbley!