github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/client/README.md (about)

     1  # Go client for the Docker Engine API
     2  
     3  The `docker` command uses this package to communicate with the daemon. It can also be used by your own Go applications to do anything the command-line interface does – running containers, pulling images, managing swarms, etc.
     4  
     5  For example, to list running containers (the equivalent of `docker ps`):
     6  
     7  ```go
     8  package main
     9  
    10  import (
    11  	"context"
    12  	"fmt"
    13  
    14  	"github.com/docker/docker/api/types"
    15  	"github.com/docker/docker/client"
    16  )
    17  
    18  func main() {
    19  	cli, err := client.NewEnvClient()
    20  	if err != nil {
    21  		panic(err)
    22  	}
    23  
    24  	containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{})
    25  	if err != nil {
    26  		panic(err)
    27  	}
    28  
    29  	for _, container := range containers {
    30  		fmt.Printf("%s %s\n", container.ID[:10], container.Image)
    31  	}
    32  }
    33  ```
    34  
    35  [Full documentation is available on GoDoc.](https://godoc.org/github.com/docker/docker/client)