Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker entrypoint running bash script gets "permission denied"

Tags:

bash

shell

docker

I'm trying to dockerize my node.js app. When the container is built I want it to run a git clone and then start the node server. Therefore I put these operations in a .sh script. And run the script as a single command in the 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"]  

My docker-entrypoint.sh looks like this:

git clone git@<repo>.git git add remote upstream git@<upstream_repo>.git  /usr/bin/node server.js 

After building this image and run:

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

I'm getting:

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

I shell into the container and the permission of docker-entrypoint.sh is:

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

three questions:

  1. Does my bash script have wrong syntax?

  2. How do I change the permission of a bash file before adding it into an image?

  3. What's the best way to run multiple git commands in entrypoint without using a bash script?

Thanks.

like image 599
Calvin Hu Avatar asked Aug 10 '16 20:08

Calvin Hu


People also ask

How do I fix permission denied docker?

If running elevated Docker commands does not fix the permission denied error, verify that your Docker Engine is running. Similar to running a docker command without the sudo command, a stopped Docker Engine triggers the permission denied error. How do you fix the error? By restarting your Docker engine.

How do I run a shell script in Dockerfile ENTRYPOINT?

Step 1: Create a script.sh file and copy the following contents. Step 2: You should have the script.sh is the same folder where you have the Dockerfile. Create the Dockerfile with the following contents which copy the script to the container and runs it part of the ENTRYPOINT using the arguments from CMD.

Why is bash permission denied?

The shell script permission denied error occurs when the shell script you're trying to run doesn't have the permissions to execute. Linux tells you about the problem by showing bash: ./program_name: permission denied on your Linux terminal. Linux and other such OSs are very much concerned about its' security.

Does ENTRYPOINT override CMD in docker?

Docker Entrypoint ENTRYPOINT is the other instruction used to configure how the container will run. Just like with CMD, you need to specify a command and parameters. However, in the case of ENTRYPOINT we cannot override the ENTRYPOINT instruction by adding command-line parameters to the `docker run` command.


1 Answers

  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).

like image 141
Charles Duffy Avatar answered Oct 20 '22 23:10

Charles Duffy