Mac OS X Dockerfile中RUN shell脚本的问题



我正在尝试将Docker与我的macOS Catalina v10.15.4一起使用

当我在Dockerfile中尝试RUN ./test.sh时,出现了一些错误。

这是我的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

我在macOS中查看了test.shfile test.sh的信息。

收到这个:

test.sh: POSIX shell script text executable, ASCII text, with CRLF line terminators

test.sh脚本包含file test.sh输出中指定的Windows行结尾。将它们转换为Unix行结尾:

$ dos2unix  test.sh
dos2unix: converting file test.sh to Unix format...

最新更新