standard_init_linux.go:190: exec user process caused "no such file or directory" - Docker

237,917

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.

Share:
237,917

Related videos on Youtube

gamechanger17
Author by

gamechanger17

Updated on April 01, 2022

Comments

  • gamechanger17
    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
    Gouravmoy Mohanty almost 6 years
    Worked 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
    Jonathan Czitkovics almost 6 years
    I 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
    Sweet Chilly Philly over 5 years
    Perfect! I had a .sh file added which was being run from my Dockerfile. I replaced the line endings and Ta Da. Thank you
  • Opsse
    Opsse over 5 years
    Can you explain why and when the "sh" is necessary? I saw many example working without.
  • tuomastik
    tuomastik about 5 years
    @Opsse Without "sh", normal shell processing does not happen source
  • Tobo
    Tobo about 5 years
    I 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
    truthblue82 almost 5 years
    I have the same problem and resolve it as your advice. Thank you very much!
  • Manuel Rony Gomes
    Manuel Rony Gomes over 4 years
    Thanks! For my go application in scratch image, had to rebuild using CGO_ENABLED=0
  • KirKone
    KirKone over 4 years
    @JonathanCzitkovics maybe you should check your git config and the settings for your code editor
  • inix
    inix over 4 years
    My Case: 1.Executable binary is build from alpine,but base image that running go command is debian,so error occurred.
  • ironrainbow
    ironrainbow over 4 years
    Thank you! It worked well! I was suffering from the same issue .
  • Emil G
    Emil G over 4 years
    I 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
    hashlock almost 4 years
    This! Should be in bold on Apline's Docker Hub page.
  • morpheuz
    morpheuz almost 4 years
    Turns 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 script bash by sh and problem solved.
  • Madhan Ganesh
    Madhan Ganesh almost 4 years
    within Dockerfile this is, add ENV CGO_ENABLED=0 before the go build line. This worked for me.
  • BMW
    BMW almost 4 years
    so in Dockerfile, it should be: RUN export CGO_ENABLED=0 && go build
  • Kip
    Kip almost 4 years
    Thanks for writing that. It made me realize I was building with ubuntu and running with alpine and alpine was presumably missing something needed.
  • Vladimir
    Vladimir over 3 years
    Yep, this is it. If you are using an entrypoint.sh file with Alpine docker image use #!/bin/sh instead of bash!
  • CoderPi
    CoderPi over 3 years
    You can find the setting in VS Code as well in the bottom right-ish
  • Pascal Z.
    Pascal Z. over 3 years
    Saved my day. Worked for me :-)
  • Gus
    Gus about 3 years
    A 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
    Roman Puchkovskiy about 3 years
    In 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
    alphayax about 3 years
    Thanks, you save my day. Please note you can oneline this : RUN CGO_ENABLED=0 go build
  • Pxnt
    Pxnt about 3 years
    Another option is dos2unix. Make sure to check all directories, as I've had to update several .sh files before it would finally work.
  • Redtama
    Redtama about 3 years
    Thank the heavens for this answer! You have saved my neck good sir. I toss a coin to you!
  • Ron7
    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
    Victor Tavares almost 3 years
    Worked for me for running on windows a node alpine container using docker-compose created on Linux. Thanks!
  • TechDog
    TechDog almost 3 years
    Struggled for few hours...thanks Vikas for saving my time
  • Mobasshir Bhuiya
    Mobasshir Bhuiya almost 3 years
    Same 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
    Subjective Reality almost 3 years
    Best 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
    viggy28 almost 3 years
    Thanks. This is it.
  • Muhammet Ali Asan
    Muhammet Ali Asan almost 3 years
    It worked for me, without registration step.
  • Gloweye
    Gloweye over 2 years
    For which file(s?) would you need to change this? The Dockerfile?
  • Vikas Rathore
    Vikas Rathore over 2 years
    @Gloweye: no. the file you are passing in entry-point. In above case /run.sh
  • Gloweye
    Gloweye over 2 years
    @VikasRathore In that case, it might be worth including that into the answer.
  • rabejens
    rabejens over 2 years
    I always add dos2unix into my containers and run this over every text file I ADD to them. This is the most robust solution in the case other colleagues forget to change line endings in their editor.
  • Gr3at
    Gr3at over 2 years
    The 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
    doptimusprime over 2 years
    This is not much voted, but solved my problem. Thanks.
  • outdead
    outdead over 2 years
    This is my case. Thanks!
  • Mai Hai
    Mai Hai over 2 years
    I got struggle running MMSegmentation docker image. Then your solution works like a magic!
  • Jesse JunJing
    Jesse JunJing over 2 years
    Perfectly solved, you are a life savor! Thanks.
  • Andreas Forslöw
    Andreas Forslöw over 2 years
    I just want to point out that if you use a Dockerfile from docker-compose, you need to add a --build argument to your docker-compose up command, so that the CRLF->LF change actually gets built.
  • Code-Apprentice
    Code-Apprentice about 2 years
    In 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
    David Louda about 2 years
    If 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
    RamPrakash about 2 years
    man....i just wanted to let you know that you saved my day.
  • TwistedSt
    TwistedSt about 2 years
    @AndreasForslöw I appreciate you. This is the part I was missing as a docker noob.