2016-11-21 04:08:28 -05:00
# Go client for the Docker Remote 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"
2016-10-08 09:34:37 -04:00
"github.com/docker/docker/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
[Full documentation is available on GoDoc. ](https://godoc.org/github.com/docker/docker/client )