Why docker image build throws /usr/bin/env: ‘sh\r’: No such file or directory?
Asked Answered
P

1

5

Building docker image....... /usr/bin/env: ‘sh\r’: No such file or directory execution failed

complete script

#!/bin/bash
 echo "Building docker image......."
. gradle.properties
 IMAGE="$dockerRegistry/$1"
 IMAGE_TAG="$releaseVersion-$(git log -1 --pretty=%h)"
 if ./gradlew clean :$1:jibDockerBuild -x test; then
 echo "Pushing docker image...."
 docker tag $IMAGE $IMAGE:$IMAGE_TAG
 docker push $IMAGE:$IMAGE_TAG
 else
 echo "execution failed"
 exit 1
  fi
 exit 0
Prang answered 3/4, 2020 at 1:10 Comment(6)
Can you also post your Dockerfile here?Planchet
$'\r' is the carriage return. Your code is presumably saved as a DOS/Windows text file, not a UNIX one. DOS text files separate lines with a CRLF sequence ($'\r\n'), whereas UNIX text files end lines (including the last one) with a linefeed alone ($'\n').Walhalla
See the very first entry in the "Before asking about problematic code" section of stackoverflow.com/tags/bash/infoWalhalla
Does this answer your question? Are shell scripts sensitive to encoding and line endings?Walhalla
That said, it's a different program that's throwing your error, not this one. This code isn't using env or sh. Maybe it's your copy of gradlew that's checked in that way? Either way, whichever program it is, the bug is as described above.Walhalla
Add printing commands at the top of your script set -x to narrow down which command exactly fails your script.Latinalatinate
B
8

Try to adjust your file endings for gradlew file:

   dos2unix .\gradlew
Bedlam answered 14/9, 2021 at 8:56 Comment(2)
shouldn't it be: dos2unix ./gradlew?Racemose
Maybe backslash is about Windows. You can try according to your operating system.Hedelman

© 2022 - 2024 — McMap. All rights reserved.