go-dockerpty icon indicating copy to clipboard operation
go-dockerpty copied to clipboard

Cannot pipe stdout

Open raphink opened this issue 9 years ago • 1 comments

Using the following code:

package main

import (
  "fmt"

  "github.com/fgrehm/go-dockerpty"
  "github.com/fsouza/go-dockerclient"
)

func main() {
  c, err := docker.NewClient("unix:///var/run/docker.sock")
  if err != nil {
    fmt.Printf("Error creating docker client: %v", err)
  }

  container, err := c.CreateContainer(
    docker.CreateContainerOptions{
      Config: &docker.Config{
        Image: "busybox",
        Cmd:   []string{"ifconfig"},
        Tty:   true,
      },
    },
  )
  if err != nil {
    fmt.Printf("Error creating container: %v", err)
  }
  err = dockerpty.Start(c, container, &docker.HostConfig{})
  if err != nil {
    fmt.Printf("Error starting container: %v", err)
  }
}

and executing it:

$ go run main.go 
eth0      Link encap:Ethernet  HWaddr 02:42:AC:11:00:03  
          inet addr:172.17.0.3  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:acff:fe11:3/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:90 (90.0 B)  TX bytes:90 (90.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

$ go run main.go  | tee /tmp/test.log 
Error starting container: inappropriate ioctl for device

Is there a way to fix this?

raphink avatar Jun 15 '16 12:06 raphink

@fgrehm any idea? @fsouza maybe?

raphink avatar Jun 23 '16 13:06 raphink