github.com/rish1988/moby@v25.0.2+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
     4  also be used by your own Go applications to do anything the command-line
     5  interface does – running containers, pulling images, managing swarms, etc.
     6  
     7  For example, to list all containers (the equivalent of `docker ps --all`):
     8  
     9  ```go
    10  package main
    11  
    12  import (
    13  	"context"
    14  	"fmt"
    15  
    16  	"github.com/docker/docker/api/types/container"
    17  	"github.com/docker/docker/client"
    18  )
    19  
    20  func main() {
    21  	apiClient, err := client.NewClientWithOpts(client.FromEnv)
    22  	if err != nil {
    23  		panic(err)
    24  	}
    25  	defer apiClient.Close()
    26  
    27  	containers, err := apiClient.ContainerList(context.Background(), container.ListOptions{All: true})
    28  	if err != nil {
    29  		panic(err)
    30  	}
    31  
    32  	for _, ctr := range containers {
    33  		fmt.Printf("%s %s (status: %s)\n", ctr.ID, ctr.Image, ctr.Status)
    34  	}
    35  }
    36  ```
    37  
    38  [Full documentation is available on pkg.go.dev.](https://pkg.go.dev/github.com/docker/docker/client)