Reputation: 4015
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:
Does my bash script have wrong syntax?
How do I change the permission of a bash file before adding it into an image?
What's the best way to run multiple git commands in entrypoint without using a bash script?
Thanks.
Upvotes: 306
Views: 498179
Reputation: 20140
Also don't forget to update permission of your local copy as well if you have volume mapping.
docker run -p8000:8000 -v .:/django worker
Upvotes: -1
Reputation: 427
As most of our friends suggested to,YES its a permission issue and adding following line in your dockerfile should help.
chmod +x docker-entrypoint.sh
Although there is a catch If by any chance you have used volume mounts
and in your host machine it is not marked as a executable file
. the entrypoint permissions will be overridden
by the host machine file permission.
which means you chmod +x docker-entrypoint.sh
wont have any effect inside the container.
Resulting in the error docker: Error response from daemon: oci runtime error: exec: "/usr/src/app/docker-entrypoint.sh": permission denied.
To avoid this you can simply give execute permission on host machine
itself or you can just run the command using the bash i.e
ENTRYPOINT ["sh", "/docker-entrypoint.sh"]
Hope it saves someones time :)
Upvotes: 3
Reputation: 27
In my case, the path of server.js
in Dockerfile was not correct, when we give proper path to the CMD
, then you might not face this issue. build has been created successfully. just check from making directory
RUN mkdir -p /home/app
COPY . /home/app
CMD ["node", "/home/app/index.js"]
My previous version was CMD["node","index.js"]
Upvotes: -2
Reputation: 11
I had 4 mysql docker images which was the cause. Removed them all & did a fresh image install.
docker images -a | grep "mysql" | awk '{print $3}' | xargs docker rmi -f
Upvotes: 1
Reputation: 571
I faced the same issue. This works for me.
COPY ./entrypoint.sh /entrypoint
RUN sed -i 's/\r//' /entrypoint
RUN chmod +x /entrypoint
ENTRYPOINT ["/entrypoint"]
Upvotes: 5
Reputation: 5545
This problem take with me more than 3 hours finally, I just tried the problem was in removing dot from the end just.
problem was
docker run -p 3000:80 --rm --name test-con test-app .
/usr/local/bin/docker-entrypoint.sh: 8: exec: .: Permission denied
just remove dot from the end of your command line :
docker run -p 3000:80 --rm --name test-con test-app
Upvotes: 28
Reputation: 983
The problem is due to original file not having execute permission.
Check original file has permission.
run ls -al
If result get -rw-r--r--
,
run
chmod +x docker-entrypoint.sh
before docker build!
Upvotes: 47
Reputation: 149
Grant execution rights to the file docker-entrypoint.sh
sudo chmod 775 docker-entrypoint.sh
Upvotes: 10
Reputation: 3006
If you still get Permission denied
errors when you try to run your script in the docker's entrypoint, just try DO NOT use the shell form of the entrypoint:
Instead of:
ENTRYPOINT ./bin/watcher
write ENTRYPOINT ["./bin/watcher"]
:
https://docs.docker.com/engine/reference/builder/#entrypoint
Upvotes: 1
Reputation: 7378
This is a bit stupid maybe but the error message I got was Permission denied and it sent me spiralling down in a very wrong direction to attempt to solve it. (Here for example)
I haven't even added any bash script myself, I think one is added by nodejs image which I use.
FROM node:14.9.0
I was wrongly running to expose/connect the port on my local:
docker run -p 80:80 [name] . # this is wrong!
which gives
/usr/local/bin/docker-entrypoint.sh: 8: exec: .: Permission denied
But you shouldn't even have a dot in the end, it was added to documentation of another projects docker image by misstake. You should simply run:
docker run -p 80:80 [name]
I like Docker a lot but it's sad it has so many gotchas like this and not always very clear error messages...
Upvotes: 6
Reputation: 678
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 .
.
Upvotes: 4
Reputation: 3752
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"
Upvotes: 3
Reputation: 1168
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"]
Upvotes: 62
Reputation: 2025
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.
Upvotes: 106
Reputation: 295706
"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.
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.
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).
Upvotes: 387