Reputation: 69
I want to get an interactive prompt with docker-compose exec [service_name] [shell]
and to fallback on another shell if the first does not exist.
I tried to run the following command:
docker-compose exec [service_name] "(which zsh && zsh) || (which bash && bash) || (which sh && sh)"
but I got this error:
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"\\\"(which zsh && zsh) || (which bash && bash) || (which sh && sh)\\\"\": executable file not found in $PATH"
If I run
docker-compose exec [service_name] bash
(zsh/bash/sh)
it opens a bash prompt and then inside the container I run
(which zsh && zsh) || (which bash && bash) || (which sh && sh)
and it works fine, it changes the shell to zsh.
Upvotes: 4
Views: 3089
Reputation: 77059
It's not clear what the command inside the container actually is. If there is an entrypoint like /bin/sh
, then your command will need to be -c "command"
. Since I don't have your docker-compose setup, here's a docker setup that may be similar:
docker run -ti --entrypoint /bin/sh --rm alpine -c \
"(which zsh && zsh) || (which bash && bash) || (which sh && sh)"
Upvotes: 2