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 
12
  • Not able to reproduce on my Mac. I cloned the repo, cded into it, copy/paste/ran your docker build command, and it got to the ./build-binutils.sh 2.31.1 step without error. Commented Jul 31, 2021 at 14:31
  • 1
    @Hcaertnit Wow. Well thanks for testing that! At least I now know it's something wrong with my own machine. Commented Jul 31, 2021 at 14:32
  • ADD is just like COPY except it has a few nifty features like downloading URLs automatically and extracting tar archives: stackoverflow.com/a/24958548/16442705 Commented Jul 31, 2021 at 14:32
  • Let me give it a shot on Windows. Commented Jul 31, 2021 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 Commented Jul 31, 2021 at 14:34

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.