standard_init_linux.go:190: exec user process caused "no such file or directory" - Docker
Solution 1
Use notepad++, go to edit -> EOL conversion -> change from CRLF to LF.
update: For VScode users: you can change CRLF to LF by clicking on CRLF present on lower right side in the status bar
Solution 2
change entry point as below. It worked for me
ENTRYPOINT ["sh","/run.sh"]
As tuomastik pointed out in the comments, the docs require the first parameter to be the executable:
ENTRYPOINT has two forms:
ENTRYPOINT ["executable", "param1", "param2"]
(exec form, preferred)
ENTRYPOINT command param1 param2
(shell form)
Solution 3
I had the same issue when using the alpine
image.
My .sh
file had the following first line:
#!/bin/bash
Alpine does not have bash. So changing the line to
#!/bin/sh
or installing bash with
apk add --no-cache bash
solved the issue for me.
Solution 4
Suppose you face this issue while running your go binary with in alpine container. Export the following variable before building your bin
# CGO has to be disabled for alpine
export CGO_ENABLED=0
Then go build
Solution 5
In my case I had to change line ending from CRLF
to LF
for the run.sh
file and the error was gone.
Related videos on Youtube
gamechanger17
Updated on April 01, 2022Comments
-
gamechanger17 about 2 years
When I am running my docker image on windows 10. I am getting this error:
standard_init_linux.go:190: exec user process caused "no such file or directory"
my docker file is:
FROM openjdk:8 EXPOSE 8080 VOLUME /tmp ADD appagent.tar.gz /opt/app-agent ADD services.jar app.jar ADD run.sh /run.sh # Install compiler and perl stuff RUN apt-get update RUN apt-get install -y build-essential RUN apt-get install -y gcc-multilib RUN apt-get install -y perl # Install Percona Toolkit RUN apt-get install --yes percona-toolkit RUN ["chmod", "+x", "/run.sh"] ENTRYPOINT ["/run.sh"]
and the script is start with #!/bin/sh
#!/bin/sh set -e JAVA_OPTS="-Dfile.encoding=UTF-8 -Djava.security.egd=file:/dev/urandom" if [ "${APPD_APP_NAME}" != "" ]; then JAVA_AGENT="-javaagent:/opt/app-agent/javaagent.jar fi exec java ${JVM_OPTS} ${JAVA_OPTS} ${JAVA_AGENT} -jar /app.jar
Tried method1: Tried changing #!/bin/sh to #!/bin/bash but getting same error.
Tried method2: added dos2unix in docker file
RUN apt-get install -y dos2unix RUN dos2unix /run.sh
-
Gouravmoy Mohanty almost 6 yearsWorked for me. In this case, we do not even need to add #!/bin/sh in the shell script. Mentioning "sh" in the ENTRYPOINT does the job
-
Jonathan Czitkovics almost 6 yearsI have to keep fixing the same files over and over. It's like windows wants to keep me in it's ecosystem.
-
Sweet Chilly Philly over 5 yearsPerfect! I had a .sh file added which was being run from my Dockerfile. I replaced the line endings and Ta Da. Thank you
-
Opsse over 5 yearsCan you explain why and when the "sh" is necessary? I saw many example working without.
-
tuomastik about 5 years@Opsse Without
"sh"
, normal shell processing does not happen source -
Tobo about 5 yearsI did not find this option in notepad++ in 'edit tab' but I've changed it clicking on the bottom right side button written Windows( CR LF) and I changed to Unix. Thanks a lot!
-
truthblue82 almost 5 yearsI have the same problem and resolve it as your advice. Thank you very much!
-
Manuel Rony Gomes over 4 yearsThanks! For my go application in scratch image, had to rebuild using CGO_ENABLED=0
-
KirKone over 4 years@JonathanCzitkovics maybe you should check your git config and the settings for your code editor
-
inix over 4 yearsMy Case: 1.Executable binary is build from alpine,but base image that running go command is debian,so error occurred.
-
ironrainbow over 4 yearsThank you! It worked well! I was suffering from the same issue .
-
Emil G over 4 yearsI got this error when trying to build and run ckan docker images on Windows. If you run into this problem on a cloned repo, it might be useful to use the core.autocrlf setting during clone, if so, execute:
git config core.autocrlf input => (deleted the files from the repo; wasn't sure if git reset would reset the newlines) => git reset --hard
Copied from: github.com/LiveOverflow/PwnAdventure3/issues/11 -
hashlock almost 4 yearsThis! Should be in bold on Apline's Docker Hub page.
-
morpheuz almost 4 yearsTurns out that in my ENTRYPOINT script I was using
/bin/bash
as shell interpreter, but since my image is alpine based it didn't come with it. I changed in my scriptbash
bysh
and problem solved. -
Madhan Ganesh almost 4 yearswithin Dockerfile this is, add ENV CGO_ENABLED=0 before the go build line. This worked for me.
-
BMW almost 4 yearsso in Dockerfile, it should be:
RUN export CGO_ENABLED=0 && go build
-
Kip almost 4 yearsThanks for writing that. It made me realize I was building with ubuntu and running with alpine and alpine was presumably missing something needed.
-
Vladimir over 3 yearsYep, this is it. If you are using an
entrypoint.sh
file withAlpine
docker image use#!/bin/sh
instead of bash! -
CoderPi over 3 yearsYou can find the setting in VS Code as well in the bottom right-ish
-
Pascal Z. over 3 yearsSaved my day. Worked for me :-)
-
Gus about 3 yearsA better solution than disabling CGo, which can have a bunch of negative side effects, is to install the shared libraries that the Go binary is looking for. In Alpine, this can usually be achieved by adding
RUN apk add --no-cache libc6-compat
to your Dockerfile, to install the glibc compatibility libs. -
Roman Puchkovskiy about 3 yearsIn my case, the binary was built using GraalVM Native Builder, by default it is built in a 'dynamic' form which apparently requires some library not present in Alpine. After adding
--static
to build a static binary the problem vanished. -
alphayax about 3 yearsThanks, you save my day. Please note you can oneline this :
RUN CGO_ENABLED=0 go build
-
Pxnt about 3 yearsAnother option is
dos2unix
. Make sure to check all directories, as I've had to update several.sh
files before it would finally work. -
Redtama about 3 yearsThank the heavens for this answer! You have saved my neck good sir. I toss a coin to you!
-
Ron7 almost 3 years@Gus Thanks! I think you should create an answer with this as it's a better/alternative solution than disabling CGO.
-
Victor Tavares almost 3 yearsWorked for me for running on windows a node alpine container using docker-compose created on Linux. Thanks!
-
TechDog almost 3 yearsStruggled for few hours...thanks Vikas for saving my time
-
Mobasshir Bhuiya almost 3 yearsSame thing can be done using VScode, at the bottom-right corner of the IDE you can find CRLF/LF, so toggle this according to your usecaes.
-
Subjective Reality almost 3 yearsBest solution here. dos2unix can of course be installed in the dockerfile and a RUN command run on any/all files needed for the container to run. This is a common issue if building linux based images on a windows machine. i.e.
find ./src/ -iname "*.ts" | dos2unix
or whatever command works in one's circumstances. -
viggy28 almost 3 yearsThanks. This is it.
-
Muhammet Ali Asan almost 3 yearsIt worked for me, without registration step.
-
Gloweye over 2 yearsFor which file(s?) would you need to change this? The Dockerfile?
-
Vikas Rathore over 2 years@Gloweye: no. the file you are passing in entry-point. In above case /run.sh
-
Gloweye over 2 years@VikasRathore In that case, it might be worth including that into the answer.
-
rabejens over 2 yearsI always add
dos2unix
into my containers and run this over every text file IADD
to them. This is the most robust solution in the case other colleagues forget to change line endings in their editor. -
Gr3at over 2 yearsThe solution for me was also similar to the one described in the answer above and the one provided by @arulraj.net. Had to
ENV CGO_ENABLED=0 RUN go mod download RUN go build -a -installsuffix cgo -o myAppName .
and then it worked. -
doptimusprime over 2 yearsThis is not much voted, but solved my problem. Thanks.
-
outdead over 2 yearsThis is my case. Thanks!
-
Mai Hai over 2 yearsI got struggle running MMSegmentation docker image. Then your solution works like a magic!
-
Jesse JunJing over 2 yearsPerfectly solved, you are a life savor! Thanks.
-
Andreas Forslöw over 2 yearsI just want to point out that if you use a Dockerfile from docker-compose, you need to add a
--build
argument to yourdocker-compose up
command, so that the CRLF->LF change actually gets built. -
Code-Apprentice about 2 yearsIn my case, git is playing games with the line endings of the bash scripot. I probably need to check
autocrlf
or the more modern settings that I forget off the top of my head. -
David Louda about 2 yearsIf using some jetbrains IDE, these have it at the bottom right when you open the file (it probably says CRLF now, click and change it to LF as suggested (no notepad++ needed)
-
RamPrakash about 2 yearsman....i just wanted to let you know that you saved my day.
-
TwistedSt about 2 years@AndreasForslöw I appreciate you. This is the part I was missing as a docker noob.