/ bin / sh:1:/go/src/test.sh:未找到

I am trying to build this dockerfile, the file is copied successfully but I keep getting the following error:

docker build --no-cache=true -f Dockerfile-Gobase .

Sending build context to Docker daemon 34MB

Step 1/3 : FROM golang:1.11.2 ---> df6ac9d1bf64

Step 2/3 : COPY ./test.sh /go/src/ ---> 38a538f0289d

Step 3/3 : RUN (ls -l /go/src/ && cd /go/src/ && /go/src/test.sh) ---> Running in 089de53d11f0

total 4

-rwxr-xr-x 1 root root 34 Jan 24 03:22 test.sh

/bin/sh: 1: /go/src/test.sh: not found

The command '/bin/sh -c (ls -l /go/src/ && cd /go/src/ && /go/src/test.sh)' returned a non-zero code: 127

These are the file codes

Dockerfile-Gobase

FROM golang:1.11.2
COPY ./test.sh /go/src/
RUN (ls -l /go/src/ && cd /go/src/ && /go/src/test.sh)

test.sh

#!/bin/sh
echo "hello world"

You eliminated the first cause by checking that the script exists in the container with an ls. This also eliminated Linux file permissions.

Next possible cause is that your interpreter isn't in the container, but showing the script we see that it's #!/bin/sh. And /bin/sh is included with your base image.

What's left that I can think of are windows line feeds in the file, a missing library somewhere, or perhaps security tools like SE Linux/AppArmor with a strict configuration. In this case, it looks like windows line feeds were there cause. You just need to configure your editor to output with Linux style line feeds. Otherwise Linux is looking for /bin/sh\R to run (where \R is the carriage return), and that command does not exist.

This is included in my DockerCon 18 talk which includes lots of other tips you may find useful when starting out.