我想编写一个程序,允许用户选择一个正在运行的docker容器,并为其提供一个交互式shell。我想要的程序流程大致如下:
- user runs program from bash -
./my_program
- user is given an
interactive cli they can use to choose which docker container to
exec
into - when user chooses container, something like
docker exec -it <CONTAINER_ID> bash
is run frommy_program
,my_program
exits, and the user is transferred into a shell session of the docker container as if they had manually rundocker exec -it <CONTAINER_ID> bash
我正在使用以下代码从golang尝试此操作:
rv, err := exec.Command("docker", "exec", "-it", containerId, "bash").Output()
log.Infof("RV: %v", rv)
if err != nil {
log.Errorf("Error exec-ing into container: %s", err)
}
并看到以下输出:
RV: []
Error exec-ing into container: exit status 1
I'm trying with err := exec.Command("docker", "exec", "-it", containerId, "bash").Run()
as well and see the same error.
我该如何创建这样的程序或调试当前发生的事情?