This is caused by moby/moby#12845
package main
import (
"fmt"
"io/ioutil"
"github.com/docker/engine-api/client"
"github.com/docker/engine-api/types"
"golang.org/x/net/context"
)
// Some basic nginx container running
const ContainerID string = "ce5d8b318ca0"
func main() {
c, _ := client.NewClient("unix:///var/run/docker.sock", "", nil, nil)
body, _ := c.ContainerLogs(context.Background(), ContainerID, types.ContainerLogsOptions{
ShowStdout: true,
ShowStderr: true,
})
defer body.Close()
// This line causes ContainerExecStart to fail with
// Error response from daemon: http: Hijack is incompatible with use of CloseNotifier
_, _ = ioutil.ReadAll(body)
exec, _ := c.ContainerExecCreate(context.Background(), ContainerID, types.ExecConfig{
Cmd: []string{"date"},
})
err := c.ContainerExecStart(context.Background(), exec.ID, types.ExecStartCheck{})
fmt.Println(err)
}
$ go run engine-api-bug.go
Error response from daemon: http: Hijack is incompatible with use of CloseNotifier
How can I fix this with engine-api?