3

I am trying to use ENTRYPOINT and whenever I do that I am getting an error as no such file or directory

Dockerfile:

FROM ubuntu:18.04

COPY . /home

COPY docker-entrypoint.sh /usr/local/bin/

RUN ln -s /usr/local/bin/docker-entrypoint.sh

WORKDIR /home
RUN chmod 777 /usr/local/bin/docker-entrypoint.sh

ENTRYPOINT ["docker-entrypoint.sh"]

CMD ["/bin/bash"]

I have tried giving it permission, tried running it with absolute path also tried this, tried it with #!/bin/bash & #!/bin/sh and in the end, I still get the file not found error.

I am not sure what the problem is.

Akshay
  • 2,622
  • 1
  • 38
  • 71
  • It looks like your docker-entrypoint.sh is in `/usr/local/bin` but you switch with `Workdir` to the `/home` directory. If you want use `docker-entrypoint.sh` in the home directory you have to copy the file to this directory. – d-h-e Apr 03 '19 at 06:08
  • That shouldn't be a problem too because when I do `COPY . /home` it also copies this file and the entry point should be able to do it right? – Akshay Apr 03 '19 at 06:10
  • What's the full error message, and what base image are you using? – Hans Musgrave Apr 03 '19 at 06:11
  • Sorry, updated it. I am using `ubuntu:18.04` – Akshay Apr 03 '19 at 06:15
  • and the error message os `standard_init_linux.go:207: exec user process caused "no such file or directory"` – Akshay Apr 03 '19 at 06:16
  • I am able to build it, but I am not able to run it – Akshay Apr 03 '19 at 06:17

1 Answers1

2

The question you asked: I don't remember exactly why, but the file isn't being found because you're calling it docker-entrypoint.sh rather than ./docker-entrypoint.sh.

The question you'll ask soon: That doesn't entirely fix your problem. You've added execute privileges to the copy of docker-entrypoint.sh in /usr/local/bin, but there's another copy of the file in /home that gets found first and doesn't have execute privileges. You'll get a permissions error when you try to use it. An easy workaround (depending on what you want to do) consists of a modified entrypoint:

ENTRYPOINT ["/bin/bash", "docker-entrypoint.sh"]

Extra details if you'll be using Docker a lot: Being able to enter a container or image to examine its contents is invaluable. For ubuntu-based images, write down the following line somewhere (replace bash with sh for basically every other linux OS):

docker run -it --rm --entrypoint=bash my_image_name

This will open up a shell in that image and let you play around in the same environment the Dockerfile is running in and debug whatever is causing you problems.

Hans Musgrave
  • 6,613
  • 1
  • 18
  • 37
  • Ya, this did help. I'll keep that in mind. Thank you. – Akshay Apr 03 '19 at 06:56
  • But now Ican't get into bash with `docker run -ti container bash` – Akshay Apr 03 '19 at 06:57
  • When you specify an `ENTRYPOINT` in the Dockerfile, you need to explicitly override it when running *images*, and the syntax is slightly different than when performing similar maneuvers on *containers*: Compare `docker run -ti --entrypoint=bash image_name` with `docker exec -ti container_name bash`. – Hans Musgrave Apr 03 '19 at 06:59
  • If that's what you're asking? If you're asking about combining ENTRYPOINT and CMD to get default arguments or whatnot, that's beyond the scope of a stackoverflow comment, and you'll want to search for or ask another question and/or read the documentation; the documentation is pretty solid on this one. – Hans Musgrave Apr 03 '19 at 07:02
  • never mind I had to do this -> https://stackoverflow.com/questions/39082768/what-does-set-e-and-exec-do-for-docker-entrypoint-scripts – Akshay Apr 03 '19 at 07:03