title: Programmatically check if Docker container process ended with non-zero status
body: <p>I'm working on a Go application which starts some Docker containers using Go Docker SDK. I need to check if containers' processes exit with zero (success) status code.</p>
  
  <p>Here's the minimal working example:</p>
  
  <pre><code>package main
  
  import (
      "context"
      "io"
      "log"
      "os"
  
      "github.com/docker/docker/api/types"
      "github.com/docker/docker/api/types/container"
      "github.com/docker/docker/client"
  )
  
  func main() {
      ctx := context.Background()
  
      cli, err := client.NewEnvClient()
      if err != nil {
          log.Fatal(err)
      }
  
      reader, err := cli.ImagePull(
          ctx,
          "docker.io/library/alpine",
          types.ImagePullOptions{},
      )
      if err != nil {
          log.Fatal(err)
      }
      io.Copy(os.Stdout, reader)
  
      resp, err := cli.ContainerCreate(ctx, &amp;container.Config{
          Image: "alpine",
          Cmd:   []string{"sh", "-c", "echo hello world; return 1"},
          Tty:   true,
      }, nil, nil, "")
      if err != nil {
          log.Fatal(err)
      }
  
      err = cli.ContainerStart(
          ctx,
          resp.ID,
          types.ContainerStartOptions{},
      )
      if err != nil {
          log.Fatal(err)
      }
  
      statusCh, errCh := cli.ContainerWait(
          ctx,
          resp.ID,
          container.WaitConditionNotRunning,
      )
      select {
      case err := &lt;-errCh:
          if err != nil {
              log.Fatal(err)
          }
      case &lt;-statusCh:
      }
  
      out, err := cli.ContainerLogs(
          ctx,
          resp.ID,
          types.ContainerLogsOptions{ShowStdout: true},
      )
      if err != nil {
          log.Fatal(err)
      }
  
      io.Copy(os.Stdout, out)
  }
  </code></pre>
  
  <p>As you can see, the process in the container ends with non-zero status (<code>sh -c "echo hello world; return 1"</code>). However, it doesn't log any fatal errors and simply displays <code>hello world</code> when built and executed:</p>
  
  <pre><code>{"status":"Pulling from library/alpine","id":"latest"}
  {"status":"Digest: sha256:7043076348bf5040220df6ad703798fd8593a0918d06d3ce30c6c93be117e430"}
  {"status":"Status: Image is up to date for alpine:latest"}
  hello world
  </code></pre>
  
  <p>How can I check that container process exited with non-zero status using Docker Go SDK?</p>