Files
moby/client
Sebastiaan van Stijn 5819d10989 client: deprecate ContainerListOptions.Latest
The `--latest` option was implemented in [moby@b295239] as a CLI shortcut
for `--last=1`.

However, as part of a large refactor of the client in [moby@d05aa41], a
`ContainerListOptions` type was introduced, which contained a `Latest`
field.

This field was never used, as the `Latest` option was handled in the CLI,
and had no corresponding option for the API (other than `limit`).

This patch deprecates the field as it is non-functional.

[moby@b295239]: b295239de2
[moby@d05aa41]: d05aa418b0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-01-23 14:49:59 +01:00
..
2025-12-16 11:03:58 +00:00
2026-01-20 16:12:51 +01:00
2026-01-20 16:12:51 +01:00
2025-11-12 17:53:36 +01:00
2025-12-05 15:57:55 +01:00
2025-11-12 17:53:36 +01:00
2025-11-12 17:53:36 +01:00
2025-11-27 12:05:27 +01:00
2025-11-12 17:53:36 +01:00
2025-11-12 17:53:36 +01:00
2025-11-12 17:53:36 +01:00
2025-11-12 17:53:36 +01:00

Go client for the Docker Engine API

PkgGoDev GitHub License Go Report Card OpenSSF Scorecard OpenSSF Best Practices

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 or pushing images, etc.

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

package main

import (
	"context"
	"fmt"

	"github.com/moby/moby/client"
)

func main() {
	// Create a new client that handles common environment variables
	// for configuration (DOCKER_HOST, DOCKER_API_VERSION), and does
	// API-version negotiation to allow downgrading the API version
	// when connecting with an older daemon version.
	apiClient, err := client.New(client.FromEnv)
	if err != nil {
		panic(err)
	}
	defer apiClient.Close()

	// List all containers (both stopped and running).
	result, err := apiClient.ContainerList(context.Background(), client.ContainerListOptions{
		All: true,
	})
	if err != nil {
		panic(err)
	}

	// Print each container's ID, status and the image it was created from.
	fmt.Printf("%s  %-22s  %s\n", "ID", "STATUS", "IMAGE")
	for _, ctr := range result.Items {
		fmt.Printf("%s  %-22s  %s\n", ctr.ID, ctr.Status, ctr.Image)
	}
}

Full documentation is available on pkg.go.dev.