This is quite strange.
I have a structure like this
app/
CLI/
someOtherFolder/
thingIwantToRun.py
tests.Dockerfile
Dockerfile
README.md
gunicorn.conf
This is what my Dockerfile looks like
FROM python:3.6
WORKDIR /app
COPY ./requirements.txt /.requirements.txt
# Install any needed packages specified in requirements.txt
RUN pip install -r /.requirements.txt
COPY gunicorn.conf /gunicorn.conf
COPY . /app
EXPOSE 8000
RUN ls
ENV FLASK_ENV=development
CMD ["python ./someOtherFolder/thingIwantToRun.py"]
This gives me this error when I start the container -
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"ls ./someOtherFolder\": stat ls ./someOtherFolder: no such file or directory": unknown.
When I change the CMD command into something else which doesn't fail and I jump into the container I see that my folder is indeed there.
When I add a RUN ls into my Dockerfile, I can still see my folder.
If it exists, why can't I run it?
UPDATE -
If I move thingIWantToRun.py into the top level folder and change my Docker CMD to
CMD [python thingIWantToRun.py]
I see the same issue. However, I can ssh into the container and verify that the file is there.
The problem is how you are running the CMD command. It is something like this:
CMD ["executable", "param1", "param2"]
ref: https://docs.docker.com/engine/reference/builder/#cmd
In that sense actual command should be
CMD ["python", "./someOtherFolder/thingIwantToRun.py"]
Docker tries to find the executable part (first item of the array) and run it, and passes rest of the array items (param1, param2) to it. If you look closer to the error is prints
... process caused "exec: \"ls ./someOtherFolder\": stat ls ./someOtherFolder: no such file or directory"
It says that ls ./someOtherFolder is not a file or directory and it can't exec it! Which is the first item of the array, the executable!
Here ls should be first item and ./someOtherFolder should be second item of array for CMD command.
You need to use the CMD command something like this:
CMD ["python", "./someOtherFolder/thingIwantToRun.py"]
Related
I'm kinda stuck exploring Docker features in order to create simple container with some Go utilities installed. I need to create image that has gosec and govulncheck utilities installed so I can run them on code in container. My petty attempt produced the following:
# syntax=docker/dockerfile:1
FROM golang:1.19-alpine
WORKDIR /app
ENV GO111MODULE=on
# copying my code to check
COPY go.mod ./
COPY go.sum ./
RUN go mod download
COPY *.go ./
RUN go build -o /docker-gs-ping
RUN apk add --no-cache git
RUN go install github.com/securego/gosec/v2/cmd/gosec#latest
RUN go install golang.org/x/vuln/cmd/govulncheck#latest
EXPOSE 8080
CMD [ "gosec ./..." ]
Running the container results in error:
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "gosec ./...": stat gosec ./...: no such file or directory: unknown.
ERRO[0000] error waiting for container: context canceled
It looks like I need to specify paths to installed utilities, but I couldn't make it work
This isn't a path issue; the problem is the syntax you've used in the CMD statement in your Dockerfile. You're using the JSON-format of the CMD statement; the first argument in the JSON list is the name of the command to run. You've asked Docker to run a command named gosec ./..., which of course doesn't exist.
You need to split that into multiple list items:
CMD [ "gosec", "./..." ]
Alternatively, you can use the shell form of the CMD directive:
CMD gosec ./...
Either of those will run gosec when you start the container.
I have the following Dockerfile:
FROM ubuntu:21.04
COPY keep-alive.sh $HOME/keep-alive.sh
CMD ["$HOME/keep-alive.sh"]
Yes I know its really useless but I am learning.
When I run this:
$ docker run -d --name linux-worker myorg/linux-worker
71cfc9ff7072688d1758f2ac98a8293ed2bcf77bf68f980da20237c9961aca6c
docker: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "exec: \"$HOME/keep-alive.sh\": stat $HOME/keep-alive.sh: no such file or directory": unknown.
All I want the container to do is start up and run $HOME/keep-alive.sh. Can anyone spot where I'm going awry?
The $HOME environment variable will not be set when running the COPY instruction in your Dockerfile so your script was likely placed at /keep-alive.sh instead of /root/keep-alive.sh where your CMD instruction expects it to be.
Check the logs of your build and you'll likely see that line executed like:
=> [3/3] COPY keep-alive.sh /keep-alive.sh
instead of:
=> [3/3] COPY keep-alive.sh /root/keep-alive.sh
To fix this, you can explicitly set an environment variable to use in this command:
FROM ubuntu:21.04
ENV DIR /root
COPY keep-alive.sh $DIR/keep-alive.sh
CMD ["/bin/bash", "-c", "$DIR/keep-alive.sh"]
Another change that had to be made was to specify that you want the script to be run in a shell so it will expand environment variables. See this answer for more details about this issue.
Alternatively, if you didn't want to use environment variables at all, you could change that line to this if you know the script's path:
CMD [ "/root/keep-alive.sh" ]
I'm getting executable file not found in $PATH: unknown error while trying to run docker image of golang project. Following is my docker file.
FROM golang:latest
LABEL maintainer = "Nisal Perera <xxx#sss.com>"
RUN mkdir -p /go/src/github.com/user/app/
COPY . /go/src/github.com/user/app/
WORKDIR /go/src/github.com/user/app/
RUN go get -u github.com/golang/dep/cmd/dep
#RUN dep init
RUN dep ensure
RUN go build
CMD ["go run main.go"]
The error I'm getting is the following
docker: Error response from daemon: OCI runtime create failed: container_linux.go:370: starting container process caused: exec: "go run main.go": executable file not found in $PATH: un
known.
Please help me with this. thanks
You dont need to use go run ... since you previously run go build, built file will be named after directory and looks like its app, try CMD ["./app"]
BTW the right usage of CMD in your case would be CMD ["go", "run", "main.go"], the error you have is related to CMD command its assume go run main.go is one file but it's not.
You're trying to use the CMD clause in its exec form so you have to split the command and its arguments. The accepted format is
CMD ["executable","param1","param2"]
So yours would be
CMD ["go", "run", "main.go"]
You are getting this error as the file "main.go" is not available at the working directory where it is executing the "go run main.go" command.
Please check the main.go file is available or not if yes then please define the complete path for the main.go file and try.
I have a docker image with this command:
FROM ruby:2.4-alpine
WORKDIR /usr/src/app
COPY Gemfile /usr/src/app/Gemfile
COPY Gemfile.lock /usr/src/app/Gemfile.lock
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle install --without development test
VOLUME /state
COPY . /usr/src/app/
ENTRYPOINT ["api-entrypoint.sh"]
CMD ["foreman", "start"]
it builds correctly but when I try to run bash, for example, I get this
container_linux.go:247: starting container process caused "exec: \"api-entrypoint.sh\": executable file not found in $PATH"
docker: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"api-entrypoint.sh\": executable file not found in $PATH".
I tried copy the entrypoint file, give it executable permissions as well with CMD...nothing worked
I had this problem with Docker for Windows and the solution was changing the entrypoint script file from CRLF -> LF.
I had the same problem - the entrypoint was not found, but I was sure that it was there.
It seems that you can't use single quotes ' for the entrypoint/command.
So I changed from
ENTRYPOINT ['/foo/bar/script.sh']
CMD ['run']
to
ENTRYPOINT ["/foo/bar/script.sh"]
CMD ["run"]
and it works.
/usr/src/app may not be in your path so you should include the full path to the script. You also need to ensure that your entrypoint.sh is executable, docker will copy the permissions exactly as they are on your build host, so this step may not be needed depending on your scenario.
FROM ruby:2.4-alpine
WORKDIR /usr/src/app
COPY Gemfile /usr/src/app/Gemfile
COPY Gemfile.lock /usr/src/app/Gemfile.lock
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle install --without development test
VOLUME /state
COPY . /usr/src/app/
RUN chmod 755 api-entrypoint.sh
ENTRYPOINT ["/usr/src/app/api-entrypoint.sh"]
CMD ["foreman", "start"]
Another source of issues can be your shebang, if you have /bin/bash and you don't have bash in your image/base image it will tell your that your entrypoint is not found. This is one of the issues I ran into.
In my case I had an error:
> [27/35] RUN /entrypoint.sh:
#31 0.503 /bin/sh: 1: /entrypoint.sh: not found
I just run dos2unix command and the issue gone:
dos2unix entrypoint.sh
I had a multi-stage build with a golang application where this problem occured. The golang executable was build in builder stage (alpine image) and then copied to the next stage (debian image). In the second stage the error occured: 'mygoexecutable' not found or does not exist.
The reason was that the executable was not compatible with the image of the second stage due to having some cgo references only available in the builder stage. Afaik apline uses libc and the debian images use glibc. The solution is to use compatible images or to set the environment variable CGO_ENABLED=0 (disable cgo) while building the executable.
On my case I do try to remove the EXEC command from the Dockerfile first to check if the .sh entry file exist. And I confirm that it is there.
When I try to run the .sh from inside the docker container it shows that the .sh file doesn't exist. So I try to run the .sh file using this command sh /path_to_entrypoint/your_sh_file.sh and it shows that there is an error in the .sh file.
After some researching I found the answer why there is an error on this post:
https://stackoverflow.com/a/67836849/10835742
If you use a variable in your ENTRYPOINT it might not get resolved.
e.g.
ENTRYPOINT ["$WORKING_DIR/start.sh"]
This will not do variable substitution.
ENTRYPOINT ["sh", "-c", "$WORKING_DIR/start.sh"]
I am very new to Docker and I am able to successfully create an Image from Docker file but when I pulled it and ran a docker start on that it threw following error:
Error response from daemon: oci runtime error:
container_linux.go:247: starting container process caused "exec: \"./Myfolder\": stat ./Myfolder: no such file or directory".
The only place that I mentioned /Myfolder is in docker File ENTRYPOINT
as below ENTRYPOINT ["./Myfolder"]
While my Dockerfile looks like following:
FROM microsoft/dotnet:1.1.1-runtime
WORKDIR /opt/outputDirectory
ENTRYPOINT ["./Myfolder"]
COPY output /opt/outputDirectory
and this is assuming my entry point is the ENTRYPOINT project's directory name (the one containing /bin) what could I be missing?
ENTRYPOINT specify the program that runs inside the container. You've put a directory.
See this example:
FROM microsoft/dotnet:1.0-runtime
WORKDIR /app
COPY out ./
ENTRYPOINT ["dotnet", "dotnetapp.dll"]