Files
moby/client
Sebastiaan van Stijn e0da5cb929 Merge pull request #46171 from thaJeztah/client_context
client: Client.buildRequest: use http.NewRequestWithContext
2023-08-10 21:00:13 +02:00
..
2016-09-07 11:05:58 -07:00
2023-05-19 20:38:51 +02:00
2023-07-05 23:44:17 +00:00
2022-09-28 01:58:52 +02:00
2022-11-30 17:08:00 +01:00
2022-07-29 23:05:15 +02:00
2023-06-29 00:25:21 +02:00
2018-05-20 13:07:17 +02:00
2018-02-05 16:51:57 -05:00

Go client for the Docker Engine API

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.

For example, to list running containers (the equivalent of docker ps):

package main

import (
	"context"
	"fmt"

	"github.com/docker/docker/api/types"
	"github.com/docker/docker/client"
)

func main() {
	cli, err := client.NewClientWithOpts(client.FromEnv)
	if err != nil {
		panic(err)
	}

	containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{})
	if err != nil {
		panic(err)
	}

	for _, container := range containers {
		fmt.Printf("%s %s\n", container.ID[:10], container.Image)
	}
}

Full documentation is available on GoDoc.