title: Golang docker api: can't run Exec on a container
body: <p>I am trying to run Exec Command on a docker container created via Go client for the Docker Engine API.</p>
  
  <p>Here is my code.</p>
  
  <pre><code>func main() {
      ctx := context.Background()
      cli, err := client.NewEnvClient()
      if err != nil {
          panic(err)
      }
  
      reader, err := cli.ImagePull(ctx, "docker.io/library/centos:7", types.ImagePullOptions{})
      if err != nil {
          panic(err)
      }
      io.Copy(os.Stdout, reader)
  
      resp, err := cli.ContainerCreate(ctx, &amp;container.Config{
          Image: "centos",
          //Cmd:   []string{"cat", "/etc/hosts"},
          //Tty:   true,
      }, nil, nil, "")
      if err != nil {
           panic(err)
      }
  
      if err := cli.ContainerStart(ctx, resp.ID, 
  types.ContainerStartOptions{}); err != nil {
          panic(err)
      }
  
       time.Sleep(5 * time.Second)
  
      c := types.ExecConfig{AttachStdout: true, AttachStderr: true, 
      Cmd: []string{"echo", "Hello Himanshu"}}
      execID, _ := cli.ContainerExecCreate(ctx, resp.ID, c)
      fmt.Println(execID)
  
      config := types.ExecConfig{}
      res, er := cli.ContainerExecAttach(ctx, execID.ID, config)
      if er != nil {
          fmt.Println("Some Error")
      }
  
      err = cli.ContainerExecStart(ctx,execID.ID,types.ExecStartCheck{})
      if err != nil {
          fmt.Println("Kuchh error")
      }
      content, _, _ := res.Reader.ReadLine()
      fmt.Println(string(content))
      }
  </code></pre>
  
  <p>Here I always get error: </p>
  
  <blockquote>
    <p>cannot exec in a stopped state: unknown
    or</p>
    
    <p>unable to upgrade to tcp, received 404</p>
  </blockquote>
  
  <p>Even if I use container logs, it will print whatever is supplied in RUN cmd, but not what is sent in Exec. same error will be there as well.</p>