小编Иль*_*тов的帖子

来自 golang api 的 Docker exec 命令

需要帮助。我有从 docker 容器执行命令的代码。需要正确地从 exec 命令获取标准输出。

execConfig:= types.ExecConfig{Tty:false,AttachStdout:true,AttachStderr:false,Cmd:command}
    respIdExecCreate,err := cli.ContainerExecCreate(context.Background(),dockerName,execConfig)
    if err != nil {
        fmt.Println(err)
    }
    respId,err:=cli.ContainerExecAttach(context.Background(),respIdExecCreate.ID,types.ExecStartCheck{})
    if err != nil {
        fmt.Println(err)
    }
    scanner := bufio.NewScanner(respId.Reader)
    for scanner.Scan() {
       fmt.Println(output)
}
Run Code Online (Sandbox Code Playgroud)

从输出中我看到了有趣的情况: 来自 gyazo 的屏幕

如何正确删除字节?

我只发送命令 := []string{"echo","-n", "hello word"}

go docker

4
推荐指数
1
解决办法
3048
查看次数

标签 统计

docker ×1

go ×1