2

I'm trying to run a local script in my docker host on a docker container.

I know it is possible to run it using: docker exec -i mycontainer bash < mylocal.sh, but how do I pass arguments to the mylocal.sh using this method.

Say I want to pass the script contents plus an argument like mylocal.sh argument1

I don't really want to copy the files over from host to container.

2
  • I don't really want to copy the files over from host to container. is there any real reason behind that ? If you need to execute that file from the container, why don't you just make it available there ? I have absolutely no idea how you can pass arguments to that file in the current context (and I even doubt it is possible). If you copy the script to the container (either in the image at build time or with docker copy...), then it is as easy as docker exec -i mycontainer myscript argument1 argument2.... Commented Dec 19, 2019 at 14:44
  • @Zeitounator basically I'm coding a tool to run batches on multiple containers in python. The python sdk doesn't have docker cp and if I wanted to volume mount then I would need to do that with all my instances of which I have over 20. Commented Dec 20, 2019 at 10:26

1 Answer 1

3

You can pass arguments to bash script using pipe by using -s option.

docker exec -i mycontainer bash -s argument1 argument2 < mylocal.sh
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.