Docker Community Forums

Share and learn in the Docker community.

Run bash script in container from host

Hi,

I need to use a program written by someone else within a Docker container. I have made a script file called bt.sh which runs the third party program with the correct options. It sits in a folder /root/FrMG_Files/.
I can run the script without problems from within the container (starting the container with the -it switch) with the command ./bt.sh from the folder /root/FrMG_Files.

I would like to automate the process by running the script from the windows host as part of a larger sequence.
In windows powershell, I tried to get the file list with :
docker exec -it -w /root/FrMG_Files container_id dir
This works and I see the script file.

I tried to run the script from windows powershell with many variations such as
docker exec -it -w /root/FrMG_Files container_id ./bt.sh
docker exec -it -w /root/FrMG_Files container_id './bt.sh --cmd “command” host''
docker exec -it -w /root/FrMG_Files container_id "./bt.sh"
but none of these worked.
I get the error message:
OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec format error": unknown

I guess I am missing only a small thing. I would greatly appreciate some help.

Many Thanks!

P.S. I am using Docker Desktop v19.03.12 in windows 10.

That REALLY depends on what you need that bash script to do!

For example, if the bash script just echoes some output, you could just do

docker run --rm -v $(pwd)/mybashscript.sh:/mybashscript.sh ubuntu bash /mybashscript.sh
Another possibility is that you want the bash script to install some software- say the script to install docker-compose. you could do something like

docker run --rm -v /usr/bin:/usr/bin --privileged -v $(pwd)/mybashscript.sh:/mybashscript.sh ubuntu bash /mybashscript.sh
But at this point you’re really getting into having to know intimately what the script is doing to allow the specific permissions it needs on your host from inside the container.

HI,
The script starts with an echo to checks that it works. Then it runs a syntax analyzer called frmg_shell. It does not install or modify the container in any way except storing the results and does not need permissions. frmg_shell is a perl program (10 GB in total) that is in the $PATH and can be run from any folder. Following the echo, the script is a list of commands like the one below with different FileName; where FileName is the text file to be analysed, Destination is the folder where the results should go, and conll is the format of the output.

echo "corpus FileName Destination :conll" | frmg_shell --batch

Thanks for the suggestion. I am completely new to Docker. Before I try it, I have a short question. I read that the command “run” is to build a container from an image while “exec” executes a program within an existing container. Your solution does not include the name of the existing container. Would Docker know which container I want to connect to? Thanks again.