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

心已入冬 提交于 2019-11-27 01:18:56

问题


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

回答1:


Use notepad++, go to edit -> EOL conversion -> change from CRLF to LF.




回答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)




回答3:


in my case I had to change line ending from CRLF to LF for the run.sh file and the error was gone.

I hope this helps,
Kirsten




回答4:


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.




回答5:


Replacing CRLF with LF using Notepad++

  1. Notepad++'s Find/Replace feature handles this requirement quite nicely. Simply bring up the Replace dialogue (CTRL+H), select Extended search mode (ALT+X), search for “\r\n” and replace with “\n”:
  2. Hit Replace All (ALT+A)

Rebuild and run the docker image should solve your problem.




回答6:


It's a CRLF problem. I fixed the problem using this:

git config --global core.eol lf

git config --global core.autocrlf input

find . -type f -print0 | xargs -0 dos2unix



回答7:


"No such file or directory" is coming from Linux, and I've seen the following causes:

First cause is not actually having the file inside your container. Some people try to run a command from the host without adding it to their image. Some people shadow their command by mounting a volume on top of the command they wanted to run. If you run the same container, but with a shell instead of your normal entrypoint/cmd value, and run an ls /path/to/cmd you'll see if this exists.

The next cause is running the wrong command. This often appears with json/exec formatting of the command to run that doesn't parse correctly. If you see a command trying to run ["app", or something similar, the json string wasn't parsed by Docker and Linux is trying to use a shell to parse the command as a string. This can also happen if you misorder the args, e.g. trying to run -it is a sign you tried to place flags after the image name when they must be placed before the image name.

With shell scripts, this error appears if the first line with the #! points to a command that doesn't exist inside the container. For some, this is trying to run bash in an image that only has /bin/sh. And in your case, this can be from Windows linefeeds in the script. Switching to Linux/Unix linefeeds in your editor will correct that.

With binaries, this error appears if a linked library is missing. I've seen this often when Go commands that are compiled with libc, but run on alpine with musl or scratch without any libraries at all. You need to either include all the missing libraries or statically compile your command. To see these library links, use ldd /your/app on your binary.




回答8:


Add this to your Dockerfile

RUN cat /run.sh | tr -d '\r' > /run.sh


来源:https://stackoverflow.com/questions/51508150/standard-init-linux-go190-exec-user-process-caused-no-such-file-or-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!