0

I have a container that is running with no issues. I added a bash script to compliment a couple other scripts already in the container. The docker image copy 2 scripts to /usr/local/bin and they can be accessed with docker exec -c container-name existingscript.

I added my own script to the same directory and when running the same command I get an error that exec cannot run the script: no file or directory,script not located in $PATH. I check path and sure enough, /usr/local/bin is listed. I checked permissions and the script is 755.

I then open an interactive shell with docker exec -it mycontainer bash and run /usr/local/bin/myscript and it runs with no problem.

Why can I not run the script from outside the container like I can the other two (that were included in the image). All three have almost the same functions a day do not use any special programs, one lists files, one adds files, one reads the file.

The base is Ubuntu.

EDIT: Found where I was running into the issue. Provided the answer in case anyone else happens to make the same mistake.

EDIT-2: So the script that came with the docker image to perform a couple common functions calls the image not the container so my adding the scripts to the container had no effect on the script which was why I kept getting the no file or directory error.

The line in the script in question was: docker run --rm -v "$(pwd)/config":/path/to/file -ti image_name:latest" mynewscript $@

Of course that ran against the image and NOT the container.

Once I noticed that I tried running it with exec instead of run and it ran without error, like so:

docker exec -it container_name mynewscript

1
  • Please, can you show your docker file? Commented Oct 24, 2016 at 4:57

2 Answers 2

1

The reason is "/usr/local/bin" not in your script's $PATH, you can use /usr/local/bin/myscript explicitly in your script. Or export $PATH first in the script.

Sign up to request clarification or add additional context in comments.

4 Comments

This is what is confusing to me, the other two scripts (that come with the image) execute perfectly. My script is in the same location, /usr/local/bin, and is called exactly the same way. Seems like it should work. I'll edit the question to include how it is called.
I was adding the snippets to the example and figured out where the issue was. The script on the host that calls and runs the other scripts inside the container is running against the image and not the container, so the script I am adding to the container does not exist.
@jcalton88 I think the difference comes from the owner of the script(different user different .bashrc). You can echo $PATH in scripts to find the root cause.
That wouldn't be it. The script on the host would find the other two scripts in the image with no problem but would not find my addition even though it existed in the same location (in $PATH). As soon as I rebuilt the image with the committed changes everything worked as expected . EDIT: Submitted before I was done. -- The host script would run calling the docker image and not the container, so my changes didn't exist there. I was able to replicate the same call to the container and it worked as well. Sorry if this doesn't sound coherent, I'm new to docker so I may not be using correct terms.
1

While I was adding snippets to help explain the issue I found the problem and the solution.

So I access the scripts inside the container from the host with another script that allows you to do different things based on switch case. The scripts are called against the docker image and not the container so the script I added does not actually exist in the image.

I modified the script to call the container instead of the image and it works as expected.

EDIT: I updated the question with the answer but I am adding it here as well:

So the script that came with the docker image to perform a couple common functions calls the image not the container so my adding the scripts to the container had no effect on the script which was why I kept getting the no file or directory error.

The line in the script in question was:

docker run --rm -v "$(pwd)/config":/path/to/file -ti image_name:latest" mynewscript $@

Of course that ran against the image and NOT the container.

Once I noticed that I tried running it with exec instead of run and it ran without error, like so:

docker exec -it container_name mynewscript

1 Comment

Edited the question to include the answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.