简体   繁体   中英

docker-compose exec failed: executable file not found in $PATH

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.

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)"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM