I have a running Docker container and need to start and interactive shell session inside the container and execute multiple commands inside before this. How can I do that?
I tried
docker exec -it foo bash < my_commands_to_exexute_inside_the_container.sh
and
docker run foo bash -c "echo Foo;echo Bar"
But none of this works. The first one does not execute the commands from the script and the second one does this, but closes the terminal session.
Any idea? Btw: The commands should come from outside the container. There is not file in the container with those commands.
Edit:
The following does almost exactly what I want it. The only catch is that the first command closes the shell and the second command opens it again. This causes me to lose environment variables.
docker exec -i foo bash < "cli.sh"
docker exec -it foo bash
Is there any way to achieve this behavior without closing the shell in between?
What about this?
docker run -it alpine sh -c "pwd;date;sh"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With