2

I received this error message which means something is erroring inside a bash script executed by the Dockerfile.

As an example, if something inside test.sh errors:

RUN test.sh # 16 ERROR: executor failed running [/bin/sh -c test.sh]: exit code: 127 

Question

What is the recommended way to gain visibility over the exact error message (i.e. to find out what's gone wrong) and to diagnose which line(s) of a bash script executed from a Dockerfile are problematic? Can docker be made to provide the output of the bash script so the exact error message is provided? Rather than just the somewhat cryptic:

executor failed running exit code: 127 

as seen here.

What I know so far

One way to diagnose which line(s) is playing up is to survey the script, assess which line(s) might be causing problems, and comment out the suspect line and everything after it. If the error goes away, you've found the (first) line that is a problem, and it can be addressed. Rinse and repeat until the script is error-free. But this seems more manual than one would hope.

4
  • 2
    build the image up to this build step, start a container, execute the script manually and investigate... Commented Oct 31, 2022 at 15:46
  • 2
    The shell -x option could potentially help here – add set -x inside your script, or explicitly run it with RUN sh -x your_script.sh – but "exit code: 127" sort of sounds like it's maybe a wrong-architecture image, or the script names an interpreter that's not present in your image (not all Docker images contain bash for example). Just as you've shown it it's also possible that test.sh isn't in $PATH anywhere and you need to RUN ./test.sh. Commented Oct 31, 2022 at 15:47
  • 1
    Also if you want to have line numbers for debugging you can follow this answer Commented Oct 31, 2022 at 15:49
  • @DavidMaze I found the error very quickly using RUN sh -x your_script.sh, thank you. You can make it an answer is you think it may help others. Commented Oct 31, 2022 at 15:56

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.