2016-11-15 14:45:20 -05:00
# Go client for the Docker Engine API
2016-09-12 05:41:11 -04:00
2016-10-08 09:34:37 -04:00
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.
2016-09-12 05:41:11 -04:00
2016-10-08 09:34:37 -04:00
For example, to list running containers (the equivalent of `docker ps` ):
2016-09-12 05:41:11 -04:00
```go
package main
import (
2016-09-22 03:00:30 -04:00
"context"
2016-10-08 09:34:37 -04:00
"fmt"
2016-09-12 05:41:11 -04:00
"github.com/docker/docker/api/types"
2017-04-17 18:07:56 -04:00
"github.com/docker/cli/client"
2016-09-12 05:41:11 -04:00
)
func main() {
2016-10-08 09:34:37 -04:00
cli, err := client.NewEnvClient()
2016-09-12 05:41:11 -04:00
if err != nil {
panic(err)
}
2016-10-08 09:34:37 -04:00
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{})
2016-09-12 05:41:11 -04:00
if err != nil {
panic(err)
}
2016-10-08 09:34:37 -04:00
for _, container := range containers {
fmt.Printf("%s %s\n", container.ID[:10], container.Image)
2016-09-12 05:41:11 -04:00
}
}
```
2016-10-08 09:34:37 -04:00
2017-04-17 18:07:56 -04:00
[Full documentation is available on GoDoc. ](https://godoc.org/github.com/docker/cli/client )