简体   繁体   中英

Docker: bash script works when run from terminal, but command not found error when run as entrypoint

I have a Docker image that I have used and successfully run my script and commands inside the container through the terminal in interactive mode.

This is my super simple script (just to get started):

#!/bin/bash
cd /project/dir
catkin_make

I wanted to use my bash script as the entry point, so I modified my Dockerfile to include:

ENTRYPOINT ["entryscript"]
CMD ["/bin/bash"] #I've tried replacing this with just "bash"

When I run this like docker run myimg , I get catkin_make: not found . If I remove the custom entry point from the Dockerfile and run the container like docker run -it myimg , then I can run the script successfully like bash entryscript .

Why would the command not be discoverable when running the script as an entry point, but works if the identical script is run inside the container.

You did neither show how you created the container, nor how your host system is configured - so a bit of guessing is involved.

It seems to me that the catkin_make command is a command available to bash on the host - it may well reside on the path. You could find out by running 'which catkin_make'.

Next be aware any dockerized process just shares the kernel with the outside world. It seems a completely independent filesystem. if in there no catkin_make application exists, or it is not on the path of the containerized bash it simply cannot be invoked.

To have more output in such szenarios I usually start my scripts with

#!/bin/bash -x

to automatically run in debug mode. You can remove that when you feel comfortable about your script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM