70

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

Luiz E.
  • 6,769
  • 10
  • 58
  • 98
  • 1
    I'm using `ADD` and finally setting the correct permission for my entry script i.e: `ADD entry.sh /entry.sh RUN chmod +x /entry.sh ENTRYPOINT /entry.sh` – Cyclonecode Jun 09 '17 at 14:56

8 Answers8

143

I had this problem with Docker for Windows and the solution was changing the entrypoint script file from CRLF -> LF.

dsschneidermann
  • 1,490
  • 2
  • 9
  • 4
59

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.

zarathustra
  • 1,898
  • 3
  • 18
  • 38
  • 1
    That makes a difference. Thanks! – Mike Doe Jun 18 '18 at 08:52
  • 1
    this didn't make a difference for me – Jeremy Jul 20 '18 at 20:27
  • 6
    Deep down in my mind some voice was telling me that single quote can be a problem. However, I told myself single quote/double quote all are same here. But I was so wrong. After trying different things for almost 1 hour, I changed to double quote and voila... – moshfiqur May 11 '19 at 12:51
  • 6
    The reason for this is in the Dockerfile reference: `Note: The exec form is parsed as a JSON array, which means that you must use double-quotes (“) around words not single-quotes (‘).` – trey-jones Apr 07 '20 at 18:22
  • 2
    Worst 3 hours of my life, trying to figure out why the F it wouldn't find the file, THANKS!, can't stress it enough, THANKS!! – E.Serra Sep 02 '20 at 12:35
37

/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"]
BMitch
  • 231,797
  • 42
  • 475
  • 450
  • it works locally but for some reason, when deploying on Docker Cloud I keep seeing `ERROR: api-1: Container command '/usr/src/app/api-entrypoint.sh' not found or does not exist.` – Luiz E. Jun 12 '17 at 07:49
  • Are you deploying the same image (with the same image id)? – BMitch Jun 12 '17 at 08:08
  • 55
    oh, nevermind, I found the problem: alpine images, when using an entrypoint, should have `#!/bin/sh` not `#!/bin/bash`. silly mistake – Luiz E. Jun 12 '17 at 08:11
11

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.

chpoit
  • 139
  • 1
  • 5
  • 2
    this was my case as we migrated into alpine distro, so bash needs to be replaced by ash now, just a 'b' of difference – gvasquez Mar 28 '22 at 14:03
  • 1
    This, and the upvoted comment above... at first I tried installing `bash` but ultimately the solution for me was to change `bash` to `sh` in my script file: `#!/usr/bin/env sh` ... all the errors I faced up to this point were not this clear lol. – CopyJosh Sep 22 '22 at 15:03
11

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
Ilya Rudakov
  • 111
  • 1
  • 2
3

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.

volkit
  • 1,173
  • 14
  • 21
0

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

mtirtapradja
  • 129
  • 1
  • 9
0

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"]
Radoslav
  • 1,446
  • 1
  • 16
  • 30