The command '/bin/sh returned a non-zero code:

2019-06-19 16:36发布

问题:

When I try to install a bin file manually inside a ubuntu Docker container it works perfectly,

./MyBinfile.bin

but when I try it from my Dockerfile I always get the error : The command '/bin/sh -c chmod +x /tmp/snapcenter_linux_host_plugin.bin && ./tmp/MyBinFile.bin' returned a non-zero code: 1

My Dockerfile looks like :

    FROM debian:jessie

    RUN apt-get update && apt-get install -y openjdk-7-jdk
    ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64
    RUN echo $JAVA_HOME

    COPY MyBinFile.bin /tmp/MyBinFile.bin
    RUN chmod +x /tmp/MyBinFile.bin && ./tmp/MyBinFile.bin

Can anyone help me in this case?

回答1:

You copied MyBinFile.bin to /tmp/MyBinFile.bin. Those are not the same file. If you need to run it use absolute path for the file that has executable attribute on it. So your last line should be:

RUN chmod +x /tmp/MyBinFile.bin && /tmp/MyBinFile.bin

'.' (dot) represents your current current working directory. It's recommended to always use absolute paths if you're unsure what is your cwd.

EDIT

Running your Dockerfile produces the following output:

Sending build context to Docker daemon 3.584 kB
Step 1/6 : FROM debian:jessie
 ---> 8cedef9d7368
Step 2/6 : RUN apt-get update && apt-get install -y openjdk-7-jdk
 ---> Using cache
 ---> 1a0005923f41
Step 3/6 : ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64
 ---> Using cache
 ---> 5651d50b519e
Step 4/6 : RUN echo $JAVA_HOME
 ---> Using cache
 ---> 96655235a2cf
Step 5/6 : COPY MyBinFile.bin /tmp/MyBinFile.bin
 ---> 60c79aaf5aca
Removing intermediate container cd729c315e9b
Step 6/6 : RUN chmod +x /tmp/MyBinFile.bin && /tmp/MyBinFile.bin
 ---> Running in 5db126cbd24c
/bin/sh: 1: /tmp/MyBinFile.bin: Text file busy
The command '/bin/sh -c chmod +x /tmp/MyBinFile.bin && 
/tmp/MyBinFile.bin' returned a non-zero code: 2

But if I separate your last step into two different steps:

FROM debian:jessie

RUN apt-get update && apt-get install -y openjdk-7-jdk
ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64
RUN echo $JAVA_HOME

COPY MyBinFile.bin /tmp/MyBinFile.bin
RUN chmod +x /tmp/MyBinFile.bin
RUN /tmp/MyBinFile.bin

then it executes OK.



标签: docker