如何在适用于Windows的Docker上在Alpine中运行简单的#!/ bin / sh脚本

时间:2019-05-07 10:15:18

标签: docker alpine

我正在尝试将脚本添加到高山linux docker文件中,但是无法运行该脚本。它总是导致

/bin/sh: /tmp/test.sh: not found 
The command '/bin/sh -c /tmp/test.sh' returned a non-zero code: 127 

该文件已设置了可执行标志。

Dockerfile:

FROM alpine

ADD test.sh /tmp/test.sh
RUN /tmp/test.sh

test.sh

#!/bin/sh

echo "Hello World"

输出

docker build --no-cache . 
Sending build context to Docker daemon  3.072kB 
Step 1/3 : FROM alpine 
 ---> cdf98d1859c1
Step 2/3 : ADD test.sh /tmp/test.sh
 ---> c81abfa30514 
Step 3/3 : RUN /tmp/test.sh
 ---> Running in 73b702648827 
/bin/sh: /tmp/test.sh: not found 
The command '/bin/sh -c /tmp/test.sh' returned a non-zero code: 127 

1 个答案:

答案 0 :(得分:1)

如果您使用的是Windows,请确保文件(test.sh)以Unix格式保存。