我希望获得docker-compose exec [service_name] [shell]
的交互式提示,如果第一个shell不存在,则回退到另一个shell。
我尝试运行以下命令:
docker-compose exec [service_name] "(which zsh && zsh) || (which bash && bash) || (which sh && sh)"
但是我收到了这个错误:
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"
如果我跑
docker-compose exec [service_name] bash
(zsh / bash / sh)
它会打开一个bash提示符,然后在我运行的容器中
(which zsh && zsh) || (which bash && bash) || (which sh && sh)
它工作正常,它将shell更改为zsh。
答案 0 :(得分:0)
目前尚不清楚容器内的命令究竟是什么。如果有/bin/sh
之类的入口点,则您的命令需要为-c "command"
。由于我没有你的docker-compose设置,这里的docker设置可能类似:
docker run -ti --entrypoint /bin/sh --rm alpine -c \
"(which zsh && zsh) || (which bash && bash) || (which sh && sh)"