getting permission denied in docker run - docker

I am trying using Docker using Dockerfile.
My Dockerfile as follows, where I am using debian linux system.
FROM debian:jessie
ENV DEBIAN_FRONTEND noninteractive
ARG AIRFLOW_VERSION=1.7.1.3
ENV AIRFLOW_HOME /usr/local/airflow
..
..
COPY script/entrypoint.sh /entrypoint.sh
COPY config/airflow.cfg ${AIRFLOW_HOME}/airflow.cfg
..
..
USER airflow
WORKDIR ${AIRFLOW_HOME}
ENTRYPOINT ["/entrypoint.sh"]
So when I run docker build -t test ., it build without problem.
However, when I run docker run -p 8080:8080 test.
It throws following error:
container_linux.go:247: starting container process caused "exec: \"/entrypoint.sh\": permission denied"
docker: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"/entrypoint.sh\": permission denied".
What is I am doing wrong ?

You need to change the permission of the bash file by chmod +x entrypoint.sh before calling ENTRYPOINT. So change your code to the following:
USER airflow
WORKDIR ${AIRFLOW_HOME}
RUN chmod +x entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
Rebuild the image and run the container, it should work.

Since COPY copies files including their metadata, you can also simply change the permissions of the file in the host machine (the one building the Docker image):
$ chmod +x entrypoint.sh
Then, when running docker build -t test . the copied file will have the execution permission and docker run -p 8080:8080 test should work.
Obs.: I'm not advocating this as best practice, but still, it works.

In your terminal, run "chmod +x entrypoint.sh"
or if the entrypoint.sh file is in a folder, run "chmod +x folder_name/entrypoint.sh"

I changed the location of the entrypoint in the dockerfolder and rebuild & it worked!

Related

docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process

I am trying to build this dockerfile and then run it but I'm getting this error docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "./deployment-service": permission denied: unknown.
This is my docker file, I've created the volumes and networks
FROM golang:1.19.2-alpine as builder
RUN apk add bash
RUN apk add --no-cache openssh-client ansible git
RUN mkdir /workspace
WORKDIR /workspace
COPY go.mod ./
COPY go.sum ./
RUN go mod download
COPY . ./
RUN go build -o deployment-service cmd/deployment-service/main.go
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /workspace .
ARG DEFAULT_PORT=8080
ENV PORT $DEFAULT_PORT
EXPOSE $PORT
CMD ["./deployment-service"]
this is my run command,
docker run --name=${CONTAINER_NAME} -d --rm -p ${PORT}:80 -e DEPLOYMENT_SERVICE_DATABASE_CONNECTION_URI=mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}#${MONGO_CONTAINER_NAME}:27017/ -e DEPLOYMENT_SERVICE_SERVER_SECRET_KEY=${SECRET_KEY} -e ANSIBLE_CONFIG='./jam-ansible/ansible.cfg' -e DEPLOYMENT_SERVICE_ANSIBLE_SUBMISSION_ROOT=${DEPLOYMENT_ROOT} -v ${DEPLOYMENT_VOLUME}:${DEPLOYMENT_ROOT} --network=${NETWORK_NAME} server:latest
help to get my issue solved.
looks like you need to edit the permissions of the deployment-service file.
try running
chmod a+x ./deployment-service
in the terminal then trying again.
Sometimes you may end up getting this error because you have not specified an entrypoint for your container.
You can do that using ENTRYPOINT inside the Dockerfile
Below is a .NET example:
ENTRYPOINT ["dotnet", "application.dll"]
It seems lack of permission to execute deployment-service. You can add
RUN chmod +x deployment-service
before CMD ["./deployment-service"]
In my case, I got the below error while trying to run the container using the command:
docker container run -p portnumber:portnumber amazoncorretto:17-alpine-jdk
ERROR:
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "bash": executable file not found in $PATH: unknown.
I used amazoncorretto:17-alpine-jdk docker image and in dockerfile instead of bash, I changed it to sh and it worked as bash didn't work with alpine.
Command changed from:
CMD ["bash", "-c", "java -jar test.jar"]
to:
CMD ["sh", "-c", "java -jar test.jar"]

Docker entrypoint permission denied

I am currently trying to deal with a deployment to a kubernetes cluster. The deployment keeps failing with the response
Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"/entrypoint.sh\": permission denied"
I have tried to change the permissions on the file which seem to succeed as if I ls -l I get -rwxr-xr-x as the permissions for the file.
I have tried placing the chmod command both in the dockerfile itself and prior to the image being built and uploaded but neither seems to make any difference.
Any ideas why I am still getting the error?
dockerfile below
FROM node:10.15.0
CMD []
ENV NODE_PATH /opt/node_modules
# Add kraken files
RUN mkdir -p /opt/kraken
ADD . /opt/kraken/
# RUN chown -R node /opt/
WORKDIR /opt/kraken
RUN npm install && \
npm run build && \
npm prune --production
# Add the entrypoint
COPY ./entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
USER node
ENTRYPOINT ["/entrypoint.sh"]
This error is not about entrypoint error but command inside. Always start scripts with "sh script.sh" either entrypoint or cmd. In this case it would be: ENTRYPOINT ["sh", "entrypoint.sh"]
I created a github action with a Dockerfile and entrypoint.sh file. I run command 'chmod +x' in my computer and push to github repository. I did not RUN 'chmod +x' in Dockerfile. It works.
tray docker exec -it /bin/sh

Building clean Go application in Docker

I'm trying to create Go web server into small Docker images. Ideally the clean image contains only the Go application itself (and maybe supporting web components, but not the Go-building environment).
Here is my Dockerfile:
# golang:latest as build-env
FROM golang:latest AS build-env
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN cd /app && GO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o myapp .
# go build -o myapp
FROM scratch
COPY --from=build-env /app/myapp /app/images /
EXPOSE 8080
ENTRYPOINT /myapp
It uses the Docker Builder Pattern and scratch image, which is a special docker image that's empty.
It builds OK, but when I run it, I'm getting:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown.
UPDATE:
So the ENTRYPOINT need to be changed to the exec form:
ENTRYPOINT ["/myapp"]
Having done that, I'm getting a new error:
standard_init_linux.go:207: exec user process caused "no such file or directory"
Having use a small footprint Linux image as the base (i.e. Alpine Linux) instead of scratch wouldn't help either:
$ docker run -it -p 8080:8080 go-web-docker-small
standard_init_linux.go:207: exec user process caused "no such file or directory"
$ docker run -it -p 8080:8080 go-web-docker-small /bin/sh -i
standard_init_linux.go:207: exec user process caused "no such file or directory"
How to fix it? Thx!
The last line of your Dockerfile is
ENTRYPOINT /myapp
There are two forms of the ENTRYPOINT (and CMD and RUN) instructions. An "exec form" looks like a JSON list, and provides an uninterpreted list of arguments to run as the main container process. A "shell form" does not look like a JSON list, and is implicitly wrapped in /bin/sh -c '...'.
Your ENTRYPOINT uses the shell form, and a FROM scratch image doesn't have a shell, producing the error you get. You can change this to the exec form
ENTRYPOINT ["/myapp"]
While building Dockerfile provided by you, I am getting following error:
COPY failed: stat /var/lib/docker/overlay2/cc1f8144192760ce7bf9cda7a7dfd0af16065901594c38609c813ea103cfd8d7/merged/app/images: no such file or directory
Fixed copy command and few others and image is building with following in Dockerfile
# golang:latest as build-env
FROM golang:latest AS build-env
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN cd /app && GO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o myapp .
# go build -o myapp
FROM scratch
COPY --from=build-env /app/myapp .
EXPOSE 8080
ENTRYPOINT ["./myapp"]

How to run an executable twice in a container

How do I execute an executable twice in a docker container?
For instance I need to run my application twice, the first time to initialize some stuff, and the second time to listen to a given port defined in an environment variables.
The commands from a shell would be something like this:
[j3d#gonzo test]$ kontrol -initial
[j3d#gongo test]$ kontrol
started... listening on port 6000...
Here below is my Dockerfile:
FROM golang:1.8.3 as builder
RUN go get -u github.com/golang/dep/cmd/dep
RUN go get -d github.com/koding/kite
WORKDIR ${GOPATH}/src/github.com/koding/kite
RUN ${GOPATH}/bin/dep ensure
RUN go install ./kontrol/kontrol
RUN mv ${GOPATH}/bin/kontrol /tmp
FROM busybox
ENV APP_HOME /opt/robotrader
RUN mkdir -p ${APP_HOME}
WORKDIR ${APP_HOME}
COPY --from=builder /tmp/kontrol .
ENTRYPOINT ["./kontrol", "-initial"]
CMD ["./kontrol"]
The container builds successfully... but when I start it I always get the following error message:
kontrol | standard_init_linux.go:190: exec user process caused "no such file or directory"
Any help would be really appreciated.
EDIT
Thanks to zero298 who helped me to figure out the issue, here below is a working Dockerfile:
FROM golang:1.8.3 as builder
RUN go get -u github.com/golang/dep/cmd/dep
RUN go get -d github.com/koding/kite
WORKDIR ${GOPATH}/src/github.com/koding/kite
RUN ${GOPATH}/bin/dep ensure
RUN CGO_ENABLED=0 go install ./kontrol/kontrol
RUN mv ${GOPATH}/bin/kontrol /tmp
FROM busybox
ENV APP_HOME /opt/robotrader
RUN mkdir -p ${APP_HOME}
WORKDIR ${APP_HOME}
COPY --from=builder /tmp/kontrol .
ENTRYPOINT ["./kontrol", "-initial"]
CMD ["./kontrol"]
The go application should be built with CGO_ENABLED=0 - see this post for more info.
I think you are running into a different issue than you think you are. Running your Dockerfile and then executing:
docker build -t j3d .
docker run -it --rm --name j3d-test --entrypoint sh j3d
Allows me to run my own commands from within the container.
Using ls lists out the PWD contents:
-rwxr-xr-x 1 root root 16.8M Jun 21 19:20 kontrol
Everything seems normal. However, trying to run that myself generates the following error:
sh: ./kontrol: not found
To me, this is likely similar to: Linux executable fails with “File not found” even though the file is there and in PATH.
In fact, if you instead:
Copy the compiled kontrol executable out of your builder image
Run the ubuntu container mounting the directory with the copied kontrol executable docker run -it --rm -v $PWD:/mnt/go ubuntu sh
Try to run kontrol
You will get the "correct" error which stipulates you haven't setup your keys correctly:
2018/06/21 19:56:57 cannot read public key file: open : no such file or directory
Your path forward is probably to figure out why you can't cross-compile
Create a script that runs it twice:
E.g in "startup.sh"
#!/bin/bash
# Run kontrol twice
./kontrol -initial
./kontrol
Then replace the last two lines in your Dockerfile with:
COPY startup.sh .
CMD ["./startup.sh"]
If kontrol terminates when you run it with the init flag, then you shuold just use
RUN /opt/robotrader/kontrol -init
CMD ["./kontrol"]
If it doesn't terminate, you'll have to find another way to architect your appp.

Docker Container Command cannot locate shell script

Here is my Dockerfile:
FROM debian
MAINTAINER Andrew Ford<andrew.ford#gg.com>
RUN apt-get update
COPY entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
and here is my entrypoint.sh (same directory as Dockerfile)
#!/bin/bash
echo Hello
then I ran:
docker build --no-cache=true -t test/dockerfile-sayhello .
and when I ran:
docker run test/dockerfile-sayhello
it returns:
C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: Container command '/entrypoint.sh' not found or does not exist..
I have tried googling around to try to see if I have made any obvious mistake, but so far I haven't been able to identify it. Maybe some of you can help
Edit: also ran chmod +x entrypoint.sh to give permission
I just tried with the following Dockerfile (adding the chmod)
FROM debian
MAINTAINER Andrew Ford<andrew.ford#gg.com>
RUN apt-get update
COPY entrypoint.sh /
RUN chmod 755 /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
And it works as expected.
It is not like issue 20789:
I tried to transform a Dockerfile setup from phusion/baseimage to gliderslabs/alpine. Turns out that those shell scripts use bash -- of course! Simply change to sh, as bash is not present, resulting in the above error..
The latest debian image should include bash since its default CMD is /bin/bash.

Resources