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"]
Related
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.
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"]
When I build binary and package to alpine image for airflow exporter with my Dockerfile I am getting error.
Not sure how to fix this error.
+++++ Error while docker build +++++++++
---> Running in caebfe9a04a0
stat mage.go: no such file or directory
The command '/bin/sh -c cd /go/src/github.com/airflow_exporter/; go run mage.go binary' returned a non-zero code: 1
+++++++++++++++
++++++++++++++++ My Dockerfile +++++++++++++++++
FROM golang:1.11.1 AS builder
RUN mkdir -p /go/src/github.com/airflow_exporter
ADD . /go/src/github.com/airflow_exporter
RUN cd /go/src/github.com/airflow_exporter/;
go run mage.go binary
FROM alpine:3.4
COPY --from=builder /go/src/github.com/airflow_exporter/bin/*/airflow_exporter /airflow_exporter
EXPOSE 9112
ENTRYPOINT [ "/airflow_exporter" ]
+++++++++++++++++++++++++++++++++
The first line in your docker build output shows that the binary file mage.go is not in the expected location (stat mage.go: no such file or directory). Check through the steps that lead up to reading that binary. I would look through the following:
Check that the directory from which your docker file is being run
actually contains the mage.go binary, since you are adding the
contents of your pwd to the airflow_exporter (ADD .
/go/src/github.com/airflow_exporter)
Try adding the full file path to mage.go
If the above fails, try running your own stat commands on the file throughout the process, and continue breaking down the problem from there
Im new to docker and trying to learn it.
Im following this tutorial: https://docs.docker.com/get-started/part2/#apppy
So I installed Docker on Windows.
Created 3 files, app.py, Dockefile and requirements.txt
My docker file looks like this
# Use an official Python runtime as a parent image
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
CMD ["python", "app.py"]
When I run it in powershell
docker build -t friendlybuild .
But as result it gives this:
Error response from daemon: Dockerfile parse error line 1: unknown instruction: #
Like it doesnt work
I have no idea why it doesnt work
I forgot to have a whitespace in ENTRYPOINT["java",
It should be ENTRYPOINT ["java",
I just tested the same and by default VSCode seems to save the Dockerfile with UTF-16 LE encoding.
Resaving the file as UTF-8 allowed docker build to run without error.
Solved by removing the dockerfile and creating it with Notepad instead of Visual Code
I had an extra line break in my Dockerfile. Didn't even notice it until I read some of these comments and realized it could be a problem. Originally my file was:
FROM openjdk:8
COPY . /usr/src/Main
WORKDIR /usr/src/Main
ENTRYPOINT ["java", "-Xmx700m","-classpath", ".:./resources/:./lib/*",
"org.spark.docker.demo.DockerMultilayerPerceptronClassifier"]
and the error I was seeing was:
$ docker build -t docker-classifier .
Sending build context to Docker daemon 248.3MB
Error response from daemon: Dockerfile parse error line 5: unknown instruction: "ORG.SPARK.DOCKER.DEMO.DOCKERMULTILAYERPERCEPTRONCLASSIFIER"]
Took me a while to figure it out until I read some of these comments above and looked into the line formatting and realized "org.spark.docker.demo.DockerMultilayerPerceptronClassifier"] was on a line of it's own. Once I removed the line break before it everything worked fine. I assumed the parser would ignore it.
When doing it from Windows, I had to make sure that I have line breaks in my Dockerfile configured for Linux (LF) and not for Windows (CRLF) when editing it from a text editor.
In Google Cloud Platform in console project using nano the comand work for me
1ยบ-nano
2-
# The Dockerfile defines the image's environment
# Import Python runtime and set up working directory
FROM python:2.7-alpine
WORKDIR /app
ADD . /app
# Install any necessary dependencies
RUN pip install -r requirements.txt
# Open port 80 for serving the webpage
EXPOSE 80
# Run app.py when the container launches
CMD ["python", "app.py"]
save the file...
I experienced this issue when working on a React app setup on Docker.
Sending build context to Docker daemon 1.143MB
Error response from daemon: Dockerfile parse error line 1: unknown instruction: +#
Here's how I solved it
The issue was that I had another file named Dockerfile (capital case D) which had some instructions in it, and it was conflicting with the original dockerfile (lower case d) in my project root directory.
I fixed this by deleting the Dockerfile and running the command:
docker build t myapp:latest .
to build the docker image from the dockerfile instead.
That's all.
I hope this helps
While running, appended some text in the start of the file. Removed those using vi in terminal and working fine.
i run docker compose in intellij idea, solved this by remove the number in docker parent folder name.
For mac users who face this issue:
Just edit/create Dockerfile using Python IDLE and remove extension.