I have the following command that works fine and prints foo
before returning:
docker exec -i <id> /bin/sh < echo "echo 'foo'"
I want to direct multiple commands into the container with one pipe, for example echo 'foo'
and ls /
. I have tried the following:
- This fails because it runs the commands on the host and pipes the output into the container:
{ echo "foo" ls / } | docker exec -i <id> /bin/sh
This fails because it has bad syntax. It also runs on the host:
{ echo "foo" ls / } | docker exec -i <id> /bin/sh
This one fails, but I would like to not use an array of strings anyway:
for COMMAND in 'echo "foo"' 'ls /' do docker exec -i <id> /bin/sh < echo $COMMAND done
I've also tried several other methods like piping commands into tee
or echo
but haven't had any luck. If you would like to know why I want to do this seemingly ridiculous thing, it's because:
- This is a short script that I would like to keep all in one place
- I would like to use syntax highlighting, so I don't want to store it all in a list of strings
- The container has the programs the script should run and the host does not
- This is an automatic process that I would like to trigger with crontab on the host