docker - 编译 dockerfile 时如何修复“非法选项”错误?
问题描述
我在dockerfile中有一个应用程序,需要调用一个.sh文件来下载包,但是调用这个文件时总是出错。
我的 dockerfile 是:
FROM alpine:3.12 as builder
ARG VERSION=7.16.0
ARG DISTRO=tomcat
ARG SNAPSHOT=true
ARG JMX_PROMETHEUS_VERSION=0.12.0
RUN apk add --no-cache \
bash \
ca-certificates \
maven \
tar \
wget \
xmlstarlet
COPY settings.xml download.sh camunda-run.sh camunda-tomcat.sh camunda-wildfly.sh /tmp/
RUN /tmp/download.sh
FROM alpine:3.12
RUN apk add --no-cache \
bash \
ca-certificates \
curl \
openjdk11-jre-headless \
tzdata \
tini \
xmlstarlet \
&& curl -o /usr/local/bin/wait-for-it.sh \
"https://raw.githubusercontent.com/vishnubob/wait-for-it/a454892f3c2ebbc22bd15e446415b8fcb7c1cfa4/wait-for-it.sh" \
&& chmod +x /usr/local/bin/wait-for-it.sh
RUN addgroup -g 1000 -S camunda && \
adduser -u 1000 -S camunda -G camunda -h /camunda -s /bin/bash -D camunda
WORKDIR /camunda
USER camunda
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["./camunda.sh"]
COPY --chown=camunda:camunda --from=builder /camunda .
我的 download.sh 文件看起来完全像这样:https ://github.com/camunda/docker-camunda-bpm-platform/blob/next/download.sh
运行命令时:docker build . -t servicecamundadocker/latest
我收到错误:
=> ERROR [builder 4/4] RUN /tmp/download.sh 0.2s ------
> [builder 4/4] RUN /tmp/download.sh:
#11 0.216 /bin/sh: illegal option -
------
有谁知道如何解决这个错误?谢谢
解决方案
经过大量研究,我找到了解决方案。
问题是 Windows 使用\r\n作为行尾,而 unix 只使用\n。因此,在我的download.sh文件中,有一个^M字符导致错误/bin/sh: 非法选项
解决方案是从 downlod.sh 文件中复制代码并将其转换为LF:
- 在Windows机器上使用Notepad++等文本编辑器进行转换
- 转到菜单编辑-> EOL 转换-> Unix (LF)
完成后,docker build 可以正常工作。
谢谢大家的支持。
推荐阅读
- java - 我可以避免使用“泛型”或更好的“设计模式”进行显式转换吗?
- javascript - 优化用字典替换文本的性能
- python - 如何在 Tkinter 中将 Entry() 输入的变量类型更改为浮点类型
- input - 我使用 appendChild 向开启窗口添加了一个单选按钮。但是在 MS Edge 中它不起作用
- python - 如何在循环中填充熊猫数据框?
- node.js - 使用 multer 时图像被保存为 id
- postgresql - Postgres在docker启动期间抱怨几何类型不存在,然后决定它存在
- java - 删除最后一个空行
- web-scraping - Chrome 浏览器找到对 API 的调用?他
- linux - Cron 失败并显示消息 Superset: command not found