我正在尝试使用 Docker Go lang SDK 执行一个命令(比如说“pwd”),我希望它返回容器上的工作目录。但它什么也没返回。我不确定是什么问题。 rst, err := cli.ContainerExecCreate(context.Background(), "0df7c1d9d185b1da627efb983886a12fefc32120d035b34e97c3ad13da6dd9cc", types.ExecConfig{Cmd: []string{"pwd"}})if err != nil { panic(err)}//res, err := cli.ContainerExecInspect(context.Background(), rst.ID)//print(res.ExitCode)response, err := cli.ContainerExecAttach(context.Background(), rst.ID, types.ExecStartCheck{})if err != nil { panic(err)}defer response.Close()data, _ := ioutil.ReadAll(response.Reader)fmt.Println(string(data))GOROOT=/usr/local/Cellar/go/1.13.5/libexec #gosetupGOPATH=/Users/pt/go #gosetup/usr/local/Cellar/go/1.13.5/libexec/bin/go build -o /private/var/folders/yp/hh3_03d541x0r6t7_zwqqhqr0000gn/T/___go_build_main_go /Users/pt/go/src/awesomeProject/main.go #gosetup/private/var/folders/yp/hh3_03d541x0r6t7_zwqqhqr0000gn/T/___go_build_main_go #gosetup### It does not print the working directory ###Process finished with exit code 0
1 回答
婷婷同学_
TA贡献1844条经验 获得超8个赞
这是通过以下配置解决的:
optionsCreate := types.ExecConfig{
AttachStdout: true,
AttachStderr: true,
Cmd: []string{"ls", "-a"},
}
- 1 回答
- 0 关注
- 328 浏览
添加回答
举报
0/150
提交
取消
