title: Executing docker command using golang exec fails
body: <p>I am using cmd.go (see below) to execute a docker command but it fails. I do the following steps to execute and get the following error.</p>
  
  <pre><code>go build
  sudo ./cmd
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>docker run -v ~/exp/a.out:/a.out ubuntu:14.04 /a.out -m 10m
  2014/10/16 14:32:12 exit status 1
  </code></pre>
  
  <p>On the other hand running directly as</p>
  
  <pre><code>sudo docker run -v ~/exp/a.out:/a.out ubuntu:14.04 /a.out -m 10m
  </code></pre>
  
  <p>results in the correct output of a.out.</p>
  
  <pre><code>Hello World
  </code></pre>
  
  <p>This is the code of cmd.go. How can I get it to work? Thanks!</p>
  
  <pre><code>package main
  
  import (
          "fmt"
          "log"
          "os/exec"
          "strings"
  )
  
  func ExampleCmd_Output() {
          //out, err := exec.Command("date", "--version").Output()   // This works
          //out, err := exec.Command("docker", "--version").Output() // This works
          //out, err := exec.Command(cmd, "images").Output() // Even docker images command works!
  
          cmd := "docker"
          cmdArgs := []string{"run", "-v", "~/exp/a.out:/a.out", "ubuntu:14.04", "/a.out", "-m", "10m"}
          fmt.Println(cmd + " " + strings.Join(cmdArgs, " "))
          out, err := exec.Command(cmd, cmdArgs...).Output()
          if err != nil {
                  log.Fatal(err)
          }
          fmt.Printf("%s", out)
  }
  
  func main() {
          ExampleCmd_Output()
  }
  </code></pre>
  
  <p>EDIT: After a comment, I tried executing the command "docker images". It works if I run the executable with sudo. That is, I am using the following line in the code now.</p>
  
  <pre><code>out, err := exec.Command(cmd, "images").Output()
  </code></pre>
  
  <p>After doing go build and running "sudo ./cmd", I get the output of docker images command. However, without sudo, I still get exit status 1. But with docker run command above even with sudo, I don't get an output.</p>