1

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
David Callanan
  • 5,601
  • 7
  • 63
  • 105
  • Not able to reproduce on my Mac. I cloned the repo, `cd`ed into it, copy/paste/ran your `docker build` command, and it got to the `./build-binutils.sh 2.31.1` step without error. –  Jul 31 '21 at 14:31
  • 1
    @Hcaertnit Wow. Well thanks for testing that! At least I now know it's something wrong with my own machine. – David Callanan Jul 31 '21 at 14:32
  • `ADD` is just like `COPY` except it has a few nifty features like downloading URLs automatically and extracting tar archives: https://stackoverflow.com/a/24958548/16442705 –  Jul 31 '21 at 14:32
  • Let me give it a shot on Windows. –  Jul 31 '21 at 14:32
  • 1
    @Hcaertnit I just realized, I removed that from the question :) It would be great if you cant test on windows, thanks – David Callanan Jul 31 '21 at 14:34
  • I would guess the issue may be exec bit missing on the script when cloning on windows. Try to add a `chmod +x /usr/local/src/build-binutils.sh` before the execution of the script. – zigarn Jul 31 '21 at 14:43
  • @zigarn Interesting idea, but that didn't fix it. It seems that the file itself is not found, almost as if the previous `cd` command wasn't working. – David Callanan Jul 31 '21 at 14:46
  • What's funny is that when I [inspect the container](https://stackoverflow.com/questions/26220957/how-can-i-inspect-the-file-system-of-a-failed-docker-build), the files are there! – David Callanan Jul 31 '21 at 14:49
  • And what are the permissions on the file? – zigarn Aug 01 '21 at 11:25
  • Can you edit the question to show how you did add the `chmod` and what is the output? Can you also add the procedure and result of your container inspection? – zigarn Aug 01 '21 at 11:29
  • I'd guess you included windows linefeeds in your shell script. If so, you'll want to configure git to not break scripts like that with it's automatic linefeed translation. – BMitch Aug 01 '21 at 12:09
  • @BMitch Interesting. I will check if that's the problem. – David Callanan Aug 01 '21 at 12:11

1 Answers1

1

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.

BMitch
  • 231,797
  • 42
  • 475
  • 450