programing

bash 스크립트를 실행하는 도커 진입 점이 "권한이 거부되었습니다"

nasanasas 2020. 9. 24. 07:55
반응형

bash 스크립트를 실행하는 도커 진입 점이 "권한이 거부되었습니다"


내 node.js 앱을 Dockerize하려고합니다. 컨테이너가 빌드되면 a를 실행 git clone하고 노드 서버를 시작하고 싶습니다 . 따라서 이러한 작업을 .sh 스크립트에 넣었습니다. 그리고 ENTRYPOINT에서 단일 명령으로 스크립트를 실행합니다.

FROM ubuntu:14.04

RUN apt-get update && apt-get install -y build-essential libssl-dev gcc curl npm git

#install gcc 4.9
RUN apt-get install -y software-properties-common python-software-properties
RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test
RUN apt-get update
RUN apt-get install -y libstdc++-4.9-dev

#install newst nodejs
RUN curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
RUN apt-get install -y nodejs

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

ADD package.json /usr/src/app/
RUN npm install

ADD docker-entrypoint.sh /usr/src/app/

EXPOSE 8080

ENTRYPOINT ["/usr/src/app/docker-entrypoint.sh"] 

내 docker-entrypoint.sh는 다음과 같습니다.

git clone git@<repo>.git
git add remote upstream git@<upstream_repo>.git

/usr/bin/node server.js

이 이미지를 빌드하고 실행 한 후 :

docker run --env NODE_ENV=development -p 8080:8080 -t -i <image>

나는 얻고있다 :

docker: Error response from daemon: oci runtime error: exec: "/usr/src/app/docker-entrypoint.sh": permission denied.

컨테이너에 쉘을 넣고 docker-entrypoint.sh의 권한은 다음과 같습니다.

-rw-r--r-- 1 root root 292 Aug 10 18:41 docker-entrypoint.sh

세 가지 질문 :

  1. 내 bash 스크립트에 잘못된 구문이 있습니까?

  2. 이미지에 추가하기 전에 bash 파일의 권한을 어떻게 변경합니까?

  3. bash 스크립트를 사용하지 않고 진입 점에서 여러 git 명령을 실행하는 가장 좋은 방법은 무엇입니까?

감사.


  1. "Permission denied" prevents your script from being invoked at all. Thus, the only syntax that could be possibly pertinent is that of the first line (the "shebang"), which should look like #!/usr/bin/env bash, or #!/bin/bash, or similar depending on your target's filesystem layout.

  2. Most likely the filesystem permissions not being set to allow execute. It's also possible that the shebang references something that isn't executable, but this is far less likely.

  3. Mooted by the ease of repairing the prior issues.


The simple reading of

docker: Error response from daemon: oci runtime error: exec: "/usr/src/app/docker-entrypoint.sh": permission denied.

...is that the script isn't marked executable.

RUN ["chmod", "+x", "/usr/src/app/docker-entrypoint.sh"]

will address this within the container. Alternately, you can ensure that the local copy referenced by the Dockerfile is executable, and then use COPY (which is explicitly documented to retain metadata).


An executable file needs to have permissions for execute set before you can execute it.

In your machine where you are building the docker image (not inside the docker image itself) try running:

ls -la path/to/directory

The first column of the output for your executable (in this case docker-entrypoint.sh) should have the executable bits set something like:

-rwxrwxr-x

If not then try:

chmod +x docker-entrypoint.sh

and then build your docker image again.

Docker uses it's own file system but it copies everything over (including permissions bits) from the source directories.


I faced same issue & it resolved by

ENTRYPOINT ["sh", "/docker-entrypoint.sh"]

For the Dockerfile in the original question it should be like:

ENTRYPOINT ["sh", "/usr/src/app/docker-entrypoint.sh"]

If you do not use DockerFile, you can simply add permission as command line argument of the bash:

docker run -t <image>  /bin/bash -c "chmod +x /usr/src/app/docker-entrypoint.sh; /usr/src/app/docker-entrypoint.sh"

This is an old question asked two years prior to my answer, I am going to post what worked for me anyways.

In my working directory I have two files: Dockerfile & provision.sh

Dockerfile:

FROM centos:6.8

# put the script in the /root directory of the container
COPY provision.sh /root

# execute the script inside the container
RUN /root/provision.sh

EXPOSE 80

# Default command
CMD ["/bin/bash"]

provision.sh:

#!/usr/bin/env bash

yum upgrade

I was able to make the file in the docker container executable by setting the file outside the container as executable chmod 700 provision.sh then running docker build . .

참고URL : https://stackoverflow.com/questions/38882654/docker-entrypoint-running-bash-script-gets-permission-denied

반응형