Change $PATH in ubuntu container so that it is accessible from outside the shell

Hi! I’m currently setting up a docker container to run scripts for me on the basis of the official ubuntu image. Everything works fine, scripts have been added to $PATH so that I can call them from within the shell (docker run -it image). However, the scripts are not available if I try to call them directly:

docker run image script.pl
docker: Error response from daemon: oci runtime error: exec: "detect_cnv.pl": executable file not found in $PATH.

I tried adding the directories to /etc/profile, but found out that is only being sourced once a shell is started. But also if I add them to /etc/environment they can’t be found. So the question is, where is the $PATH that I need to add my directories to?

All help is appreciated :slight_smile:

Hi,

Where is detect_cnv.pl inside container? Is it in the same directory as script.pl. I think your script.pl is getting triggered.

To see the PATH variables in the container you can run as shown below.

docker run image env | grep PATH

And instead of setting PATH variable inside /etc/profile and /etc/environment, you can just add environment variable in Dockerfile

Example:

ENV PATH=$PATH:/my/script/path/

Hope this helps.
Regards

1 Like

Thank you for the hints! I ended up defining the PATH in the Dockerfile and it works fine. However, those variables show up twice in my PATH if I use the ‘grep | PATH’ command :smiley: Not a big deal, will figure that out later.

Thanks again!