David Callanan
David Callanan

Reputation: 5800

Forked docker image not building

I am trying to fork this docker image so that if anything changes on the original it won't affect me.

I have forked the repo corresponding to that image to my own repo.

I have cloned the repo and am trying to build it:

docker build . -t davcal/gcc-cross-x86_64-elf

I am getting this error:

+ cd /usr/local/src
+ ./build-binutils.sh 2.31.1
/bin/sh: 1: ./build-binutils.sh: not found
The command '/bin/sh -c set -x  && cd /usr/local/src    && ./build-binutils.sh ${BINUTILS_VERSION}      && ./build-gcc.sh ${GCC_VERSION}' returned a non-zero code: 127

enter image description here

What makes no sense to me is that if I use the original image, it builds successfully:

FROM randomdude/gcc-cross-x86_64-elf
...

Maybe Docker Hub stores a pre-built image?

How do I fix this?

Note: I am using Windows. This shouldn't make a difference since the error originates within the container.

Edit

I tried patching the Dockerfile to chmod executable permissions to the sh files in case that was causing problems on Windows. Unfortunately, the exact same error occurs.

RUN set -x \
    && chmod +x /usr/local/src/build-binutils.sh \
    && chmod +x /usr/local/src/build-gcc.sh \
    && cd /usr/local/src \
    && ./build-binutils.sh ${BINUTILS_VERSION} \
    && ./build-gcc.sh ${GCC_VERSION}

Edit 2

Following this method, I inspected the container to see if the sh files actually exist. Here is the output.

I ran docker run --rm -it c53693f11514 bash, including the hash of the intermediate container of the previous successful step of the Dockerfile.

This is the output showing that the files do exist:

root@9b8a64ac2090:/# cd usr/local/src
root@9b8a64ac2090:/usr/local/src# ls
binutils-2.31.1  build-binutils.sh  build-gcc.sh  gcc-8.2.0

Upvotes: 1

Views: 270

Answers (1)

BMitch
BMitch

Reputation: 264761

From the described symptoms, file exists, is a shell script, and works on other machines, the "file not found" error is most likely from Winidows linefeeds being added to the file. When the Linux kernel processes a shell script, it looks at the first line, the #!/bin/sh or similar, and then finds that interpreter to run the shell script. If that interpreter isn't found, you'll get a "file not found" error.

In this case, the file it's looking for won't be /bin/sh, but instead /bin/sh\r or /bin/sh^M depending on how you want to represent the carriage return character. You can fix that for single files with a tool like dos2unix but in general, you'll want to fix git itself since there are likely other files that have had their linefeeds corrupted. For details on adjusting the behavior of git, see this post.

Upvotes: 1

Related Questions