macos - Mac OS X 中 Dockerfile 中的 RUN shell 脚本问题
问题描述
我正在尝试将 Docker 与我的macOS Catalina v10.15.4
当我尝试RUN ./test.sh
在 Dockerfile 中进行操作时,发生了一些错误。
这是我的 Dockerfile:
FROM ubuntu:18.04
RUN mkdir -p /home/rootfs/src
COPY test.sh /home/rootfs
WORKDIR /home/rootfs
RUN chmod +x test.sh && ./test.sh
当我尝试构建它时,它没有找到如下脚本:
$ docker build -t test .
Sending build context to Docker daemon 264.6MB
Step 1/5 : FROM ubuntu:18.04
---> 4e5021d210f6
Step 2/5 : RUN mkdir -p /home/rootfs/src
---> Running in d0813632475d
Removing intermediate container d0813632475d
---> 87a6e284993d
Step 3/5 : COPY test.sh /home/rootfs
---> 26d281d0002c
Step 4/5 : WORKDIR /home/rootfs
---> Running in 4c7e81a514a7
Removing intermediate container 4c7e81a514a7
---> dab2872eb15a
Step 5/5 : RUN chmod +x test.sh && ./test.sh
---> Running in a03f3e5d29b4
/bin/sh: 1: ./test.sh: not found
The command '/bin/sh -c chmod +x test.sh && ./test.sh' returned a non-zero code: 127
file test.sh
我在 macOS 中检查了 test.sh 的信息。
明白啦:
test.sh: POSIX shell script text executable, ASCII text, with CRLF line terminators
解决方案
您的test.sh
脚本包含在输出中指定的 Windows 行尾file test.sh
。将它们转换为 Unix 行尾:
$ dos2unix test.sh
dos2unix: converting file test.sh to Unix format...
推荐阅读
- python-3.x - Python在文本文件中搜索模式的有效方法
- google-chrome - 对于运行 Windows 7 的计算机,Chrome 上的 SSL 问题 NET::ERR_CERT_DATE_INVALID
- vulkan - 为什么 Vulkan 中的栅栏状态检查和重置如此缓慢?
- reactjs - Apollo 客户端重新获取非活动查询
- html - 为什么 css 中的 background-image 属性不起作用?
- php - 通过使用 php 比较 id 从另一个表中获取数据
- javascript - 如果它们是嵌套的,则无法设置 formik 错误
- unit-testing - 如何模拟querydsl查询?
- r - 如何使用 R 提高读取带有重复标签的 xml 的速度
- postgresql - 无法将触发器从 Oracle 转换为 PostgreSQL