Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No file found when using ENTRYPOINT

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.

like image 883
Akshay Avatar asked Aug 12 '26 10:08

Akshay


1 Answers

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.

like image 52
Hans Musgrave Avatar answered Aug 15 '26 01:08

Hans Musgrave