首页 > 解决方案 > 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

标签: macosdocker

解决方案


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

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

推荐阅读