From 34db3110ce09e72c74414f8096bb8dcc92124bac Mon Sep 17 00:00:00 2001 From: David Karlsson <35727626+dvdksn@users.noreply.github.com> Date: Thu, 20 Nov 2025 18:01:07 +0100 Subject: [PATCH 1/2] engine: update go sdk examples to use new moby/moby/client module Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com> --- content/reference/api/engine/sdk/_index.md | 151 +++++++++---------- content/reference/api/engine/sdk/examples.md | 141 +++++++++-------- 2 files changed, 143 insertions(+), 149 deletions(-) diff --git a/content/reference/api/engine/sdk/_index.md b/content/reference/api/engine/sdk/_index.md index ff53abd57379..e66b7774a030 100644 --- a/content/reference/api/engine/sdk/_index.md +++ b/content/reference/api/engine/sdk/_index.md @@ -26,20 +26,18 @@ installed and coexist together. ### Go SDK ```console -$ go get github.com/docker/docker/client +$ go get github.com/moby/moby/client ``` The client requires a recent version of Go. Run `go version` and ensure that you're running a currently supported version of Go. - -For more information, see [Docker Engine Go SDK reference](https://godoc.org/github.com/docker/docker/client). +For more information, see [Go client reference](https://pkg.go.dev/github.com/moby/moby/client). ### Python SDK - Recommended: Run `pip install docker`. - If you can't use `pip`: - 1. [Download the package directly](https://pypi.python.org/pypi/docker/). 2. Extract it and change to the extracted directory. 3. Run `python setup.py install`. @@ -84,53 +82,54 @@ import ( "io" "os" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/image" - "github.com/docker/docker/client" - "github.com/docker/docker/pkg/stdcopy" + "github.com/moby/moby/api/pkg/stdcopy" + "github.com/moby/moby/api/types/container" + "github.com/moby/moby/client" ) func main() { - ctx := context.Background() - cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) - if err != nil { - panic(err) - } - defer cli.Close() - - reader, err := cli.ImagePull(ctx, "docker.io/library/alpine", image.PullOptions{}) - if err != nil { - panic(err) - } - io.Copy(os.Stdout, reader) - - resp, err := cli.ContainerCreate(ctx, &container.Config{ - Image: "alpine", - Cmd: []string{"echo", "hello world"}, - }, nil, nil, nil, "") - if err != nil { - panic(err) - } - - if err := cli.ContainerStart(ctx, resp.ID, container.StartOptions{}); err != nil { - panic(err) - } - - statusCh, errCh := cli.ContainerWait(ctx, resp.ID, container.WaitConditionNotRunning) - select { - case err := <-errCh: - if err != nil { - panic(err) - } - case <-statusCh: - } - - out, err := cli.ContainerLogs(ctx, resp.ID, container.LogsOptions{ShowStdout: true}) - if err != nil { - panic(err) - } - - stdcopy.StdCopy(os.Stdout, os.Stderr, out) + ctx := context.Background() + apiClient, err := client.New(client.FromEnv) + if err != nil { + panic(err) + } + defer apiClient.Close() + + reader, err := apiClient.ImagePull(ctx, "docker.io/library/alpine", client.ImagePullOptions{}) + if err != nil { + panic(err) + } + io.Copy(os.Stdout, reader) + + resp, err := apiClient.ContainerCreate(ctx, client.ContainerCreateOptions{ + Image: "alpine", + Config: &container.Config{ + Cmd: []string{"echo", "hello world"}, + }, + }) + if err != nil { + panic(err) + } + + if _, err := apiClient.ContainerStart(ctx, resp.ID, client.ContainerStartOptions{}); err != nil { + panic(err) + } + + wait := apiClient.ContainerWait(ctx, resp.ID, client.ContainerWaitOptions{}) + select { + case err := <-wait.Error: + if err != nil { + panic(err) + } + case <-wait.Result: + } + + out, err := apiClient.ContainerLogs(ctx, resp.ID, client.ContainerLogsOptions{ShowStdout: true}) + if err != nil { + panic(err) + } + + stdcopy.StdCopy(os.Stdout, os.Stderr, out) } ``` @@ -184,31 +183,31 @@ There are a number of community supported libraries available for other languages. They haven't been tested by Docker, so if you run into any issues, file them with the library maintainers. -| Language | Library | -|:----------------------|:----------------------------------------------------------------------------| -| C | [libdocker](https://github.com/danielsuo/libdocker) | -| C# | [Docker.DotNet](https://github.com/ahmetalpbalkan/Docker.DotNet) | -| C++ | [lasote/docker_client](https://github.com/lasote/docker_client) | -| Clojure | [clj-docker-client](https://github.com/into-docker/clj-docker-client) | -| Clojure | [contajners](https://github.com/lispyclouds/contajners) | -| Dart | [bwu_docker](https://github.com/bwu-dart/bwu_docker) | -| Erlang | [erldocker](https://github.com/proger/erldocker) | -| Gradle | [gradle-docker-plugin](https://github.com/gesellix/gradle-docker-plugin) | -| Groovy | [docker-client](https://github.com/gesellix/docker-client) | -| Haskell | [docker-hs](https://github.com/denibertovic/docker-hs) | -| Java | [docker-client](https://github.com/spotify/docker-client) | -| Java | [docker-java](https://github.com/docker-java/docker-java) | -| Java | [docker-java-api](https://github.com/amihaiemil/docker-java-api) | -| Java | [jocker](https://github.com/ndeloof/jocker) | -| NodeJS | [dockerode](https://github.com/apocas/dockerode) | -| NodeJS | [harbor-master](https://github.com/arhea/harbor-master) | -| NodeJS | [the-moby-effect](https://github.com/leonitousconforti/the-moby-effect) | -| Perl | [Eixo::Docker](https://github.com/alambike/eixo-docker) | -| PHP | [Docker-PHP](https://github.com/docker-php/docker-php) | -| Ruby | [docker-api](https://github.com/swipely/docker-api) | -| Rust | [bollard](https://github.com/fussybeaver/bollard) | -| Rust | [docker-rust](https://github.com/abh1nav/docker-rust) | -| Rust | [shiplift](https://github.com/softprops/shiplift) | -| Scala | [tugboat](https://github.com/softprops/tugboat) | -| Scala | [reactive-docker](https://github.com/almoehi/reactive-docker) | -| Swift | [docker-client-swift](https://github.com/valeriomazzeo/docker-client-swift) | +| Language | Library | +| :------- | :-------------------------------------------------------------------------- | +| C | [libdocker](https://github.com/danielsuo/libdocker) | +| C# | [Docker.DotNet](https://github.com/ahmetalpbalkan/Docker.DotNet) | +| C++ | [lasote/docker_client](https://github.com/lasote/docker_client) | +| Clojure | [clj-docker-client](https://github.com/into-docker/clj-docker-client) | +| Clojure | [contajners](https://github.com/lispyclouds/contajners) | +| Dart | [bwu_docker](https://github.com/bwu-dart/bwu_docker) | +| Erlang | [erldocker](https://github.com/proger/erldocker) | +| Gradle | [gradle-docker-plugin](https://github.com/gesellix/gradle-docker-plugin) | +| Groovy | [docker-client](https://github.com/gesellix/docker-client) | +| Haskell | [docker-hs](https://github.com/denibertovic/docker-hs) | +| Java | [docker-client](https://github.com/spotify/docker-client) | +| Java | [docker-java](https://github.com/docker-java/docker-java) | +| Java | [docker-java-api](https://github.com/amihaiemil/docker-java-api) | +| Java | [jocker](https://github.com/ndeloof/jocker) | +| NodeJS | [dockerode](https://github.com/apocas/dockerode) | +| NodeJS | [harbor-master](https://github.com/arhea/harbor-master) | +| NodeJS | [the-moby-effect](https://github.com/leonitousconforti/the-moby-effect) | +| Perl | [Eixo::Docker](https://github.com/alambike/eixo-docker) | +| PHP | [Docker-PHP](https://github.com/docker-php/docker-php) | +| Ruby | [docker-api](https://github.com/swipely/docker-api) | +| Rust | [bollard](https://github.com/fussybeaver/bollard) | +| Rust | [docker-rust](https://github.com/abh1nav/docker-rust) | +| Rust | [shiplift](https://github.com/softprops/shiplift) | +| Scala | [tugboat](https://github.com/softprops/tugboat) | +| Scala | [reactive-docker](https://github.com/almoehi/reactive-docker) | +| Swift | [docker-client-swift](https://github.com/valeriomazzeo/docker-client-swift) | diff --git a/content/reference/api/engine/sdk/examples.md b/content/reference/api/engine/sdk/examples.md index 366a9cbfc251..2f5f1e715164 100644 --- a/content/reference/api/engine/sdk/examples.md +++ b/content/reference/api/engine/sdk/examples.md @@ -41,21 +41,20 @@ import ( "io" "os" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/image" - "github.com/docker/docker/client" - "github.com/docker/docker/pkg/stdcopy" + "github.com/moby/moby/api/pkg/stdcopy" + "github.com/moby/moby/api/types/container" + "github.com/moby/moby/client" ) func main() { ctx := context.Background() - cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + apiClient, err := client.New(client.FromEnv) if err != nil { panic(err) } - defer cli.Close() + defer apiClient.Close() - reader, err := cli.ImagePull(ctx, "docker.io/library/alpine", image.PullOptions{}) + reader, err := apiClient.ImagePull(ctx, "docker.io/library/alpine", client.ImagePullOptions{}) if err != nil { panic(err) } @@ -66,29 +65,31 @@ func main() { // If stdout is not required, consider using io.Discard instead of os.Stdout. io.Copy(os.Stdout, reader) - resp, err := cli.ContainerCreate(ctx, &container.Config{ + resp, err := apiClient.ContainerCreate(ctx, client.ContainerCreateOptions{ + Config: &container.Config{ + Cmd: []string{"echo", "hello world"}, + Tty: false, + }, Image: "alpine", - Cmd: []string{"echo", "hello world"}, - Tty: false, - }, nil, nil, nil, "") + }) if err != nil { panic(err) } - if err := cli.ContainerStart(ctx, resp.ID, container.StartOptions{}); err != nil { + if _, err := apiClient.ContainerStart(ctx, resp.ID, client.ContainerStartOptions{}); err != nil { panic(err) } - statusCh, errCh := cli.ContainerWait(ctx, resp.ID, container.WaitConditionNotRunning) + wait := apiClient.ContainerWait(ctx, resp.ID, client.ContainerWaitOptions{}) select { - case err := <-errCh: + case err := <-wait.Error: if err != nil { panic(err) } - case <-statusCh: + case <-wait.Result: } - out, err := cli.ContainerLogs(ctx, resp.ID, container.LogsOptions{ShowStdout: true}) + out, err := apiClient.ContainerLogs(ctx, resp.ID, client.ContainerLogsOptions{ShowStdout: true}) if err != nil { panic(err) } @@ -156,36 +157,34 @@ import ( "io" "os" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/image" - "github.com/docker/docker/client" + "github.com/moby/moby/client" ) func main() { ctx := context.Background() - cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + apiClient, err := client.New(client.FromEnv) if err != nil { panic(err) } - defer cli.Close() + defer apiClient.Close() imageName := "bfirsh/reticulate-splines" - out, err := cli.ImagePull(ctx, imageName, image.PullOptions{}) + out, err := apiClient.ImagePull(ctx, imageName, client.ImagePullOptions{}) if err != nil { panic(err) } defer out.Close() io.Copy(os.Stdout, out) - resp, err := cli.ContainerCreate(ctx, &container.Config{ + resp, err := apiClient.ContainerCreate(ctx, client.ContainerCreateOptions{ Image: imageName, - }, nil, nil, nil, "") + }) if err != nil { panic(err) } - if err := cli.ContainerStart(ctx, resp.ID, container.StartOptions{}); err != nil { + if _, err := apiClient.ContainerStart(ctx, resp.ID, client.ContainerStartOptions{}); err != nil { panic(err) } @@ -233,24 +232,23 @@ import ( "context" "fmt" - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/client" + "github.com/moby/moby/client" ) func main() { ctx := context.Background() - cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + apiClient, err := client.New(client.FromEnv) if err != nil { panic(err) } - defer cli.Close() + defer apiClient.Close() - containers, err := cli.ContainerList(ctx, containertypes.ListOptions{}) + containers, err := apiClient.ContainerList(ctx, client.ContainerListOptions{}) if err != nil { panic(err) } - for _, container := range containers { + for _, container := range containers.Items { fmt.Println(container.ID) } } @@ -303,27 +301,26 @@ import ( "context" "fmt" - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/client" + "github.com/moby/moby/client" ) func main() { ctx := context.Background() - cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + apiClient, err := client.New(client.FromEnv) if err != nil { panic(err) } - defer cli.Close() + defer apiClient.Close() - containers, err := cli.ContainerList(ctx, containertypes.ListOptions{}) + containers, err := apiClient.ContainerList(ctx, client.ContainerListOptions{}) if err != nil { panic(err) } - for _, container := range containers { + for _, container := range containers.Items { fmt.Print("Stopping container ", container.ID[:10], "... ") noWaitTimeout := 0 // to not wait for the container to exit gracefully - if err := cli.ContainerStop(ctx, container.ID, containertypes.StopOptions{Timeout: &noWaitTimeout}); err != nil { + if _, err := apiClient.ContainerStop(ctx, container.ID, client.ContainerStopOptions{Timeout: &noWaitTimeout}); err != nil { panic(err) } fmt.Println("Success") @@ -377,21 +374,20 @@ import ( "io" "os" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/client" + "github.com/moby/moby/client" ) func main() { ctx := context.Background() - cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + apiClient, err := client.New(client.FromEnv) if err != nil { panic(err) } - defer cli.Close() + defer apiClient.Close() - options := container.LogsOptions{ShowStdout: true} + options := client.ContainerLogsOptions{ShowStdout: true} // Replace this ID with a container that really exists - out, err := cli.ContainerLogs(ctx, "f1064a8a4c82", options) + out, err := apiClient.ContainerLogs(ctx, "f1064a8a4c82", options) if err != nil { panic(err) } @@ -439,24 +435,23 @@ import ( "context" "fmt" - "github.com/docker/docker/api/types/image" - "github.com/docker/docker/client" + "github.com/moby/moby/client" ) func main() { ctx := context.Background() - cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + apiClient, err := client.New(client.FromEnv) if err != nil { panic(err) } - defer cli.Close() + defer apiClient.Close() - images, err := cli.ImageList(ctx, image.ListOptions{}) + images, err := apiClient.ImageList(ctx, client.ImageListOptions{}) if err != nil { panic(err) } - for _, image := range images { + for _, image := range images.Items { fmt.Println(image.ID) } } @@ -502,19 +497,18 @@ import ( "io" "os" - "github.com/docker/docker/api/types/image" - "github.com/docker/docker/client" + "github.com/moby/moby/client" ) func main() { ctx := context.Background() - cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + apiClient, err := client.New(client.FromEnv) if err != nil { panic(err) } - defer cli.Close() + defer apiClient.Close() - out, err := cli.ImagePull(ctx, "alpine", image.PullOptions{}) + out, err := apiClient.ImagePull(ctx, "alpine", client.ImagePullOptions{}) if err != nil { panic(err) } @@ -572,18 +566,17 @@ import ( "io" "os" - "github.com/docker/docker/api/types/image" - "github.com/docker/docker/api/types/registry" - "github.com/docker/docker/client" + "github.com/moby/moby/api/types/registry" + "github.com/moby/moby/client" ) func main() { ctx := context.Background() - cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + apiClient, err := client.New(client.FromEnv) if err != nil { panic(err) } - defer cli.Close() + defer apiClient.Close() authConfig := registry.AuthConfig{ Username: "username", @@ -595,7 +588,7 @@ func main() { } authStr := base64.URLEncoding.EncodeToString(encodedJSON) - out, err := cli.ImagePull(ctx, "alpine", image.PullOptions{RegistryAuth: authStr}) + out, err := apiClient.ImagePull(ctx, "alpine", client.ImagePullOptions{RegistryAuth: authStr}) if err != nil { panic(err) } @@ -660,40 +653,42 @@ import ( "context" "fmt" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/client" + "github.com/moby/moby/api/types/container" + "github.com/moby/moby/client" ) func main() { ctx := context.Background() - cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + apiClient, err := client.New(client.FromEnv) if err != nil { panic(err) } - defer cli.Close() + defer apiClient.Close() - createResp, err := cli.ContainerCreate(ctx, &container.Config{ + createResp, err := apiClient.ContainerCreate(ctx, client.ContainerCreateOptions{ + Config: &container.Config{ + Cmd: []string{"touch", "/helloworld"}, + }, Image: "alpine", - Cmd: []string{"touch", "/helloworld"}, - }, nil, nil, nil, "") + }) if err != nil { panic(err) } - if err := cli.ContainerStart(ctx, createResp.ID, container.StartOptions{}); err != nil { + if _, err := apiClient.ContainerStart(ctx, createResp.ID, client.ContainerStartOptions{}); err != nil { panic(err) } - statusCh, errCh := cli.ContainerWait(ctx, createResp.ID, container.WaitConditionNotRunning) + wait := apiClient.ContainerWait(ctx, createResp.ID, client.ContainerWaitOptions{}) select { - case err := <-errCh: + case err := <-wait.Error: if err != nil { panic(err) } - case <-statusCh: + case <-wait.Result: } - commitResp, err := cli.ContainerCommit(ctx, createResp.ID, container.CommitOptions{Reference: "helloworld"}) + commitResp, err := apiClient.ContainerCommit(ctx, createResp.ID, client.ContainerCommitOptions{Reference: "helloworld"}) if err != nil { panic(err) } From 66e8d18c900c23f02801a3ce42e0546618b27089 Mon Sep 17 00:00:00 2001 From: David Karlsson <35727626+dvdksn@users.noreply.github.com> Date: Thu, 20 Nov 2025 18:09:24 +0100 Subject: [PATCH 2/2] engine: fix import path in release note for for api/pkg/stdcopy Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com> --- content/manuals/engine/release-notes/29.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/manuals/engine/release-notes/29.md b/content/manuals/engine/release-notes/29.md index cbac67589b0d..68c9dafa21ec 100644 --- a/content/manuals/engine/release-notes/29.md +++ b/content/manuals/engine/release-notes/29.md @@ -389,7 +389,7 @@ For a full list of pull requests and changes in this release, refer to the relev - Go SDK: container: remove deprecated `IsValidHealthString`. [moby/moby#50378](https://github.com/moby/moby/pull/50378) - Go SDK: container: remove deprecated `IsValidStateString`. [moby/moby#50378](https://github.com/moby/moby/pull/50378) - Go SDK: container: remove deprecated `StateStatus`, `WaitCondition`, and the related `WaitConditionNotRunning`, `WaitConditionNextExit`, and `WaitConditionRemoved` consts. [moby/moby#50378](https://github.com/moby/moby/pull/50378) -- Go SDK: deprecate `pkg/stdcopy`, which was moved to `api/stdcopy`. [moby/moby#50462](https://github.com/moby/moby/pull/50462) +- Go SDK: deprecate `pkg/stdcopy`, which was moved to `api/pkg/stdcopy`. [moby/moby#50462](https://github.com/moby/moby/pull/50462) - Go SDK: Deprecate field `NetworkSettingsBase.Bridge`, struct `NetworkSettingsBase`, all the fields of `DefaultNetworkSettings`, and struct `DefaultNetworkSettings`. [moby/moby#50848](https://github.com/moby/moby/pull/50848) - Go SDK: deprecate pkg/stringid in favour of `github.com/moby/moby/client/pkg/stringid`. [moby/moby#50504](https://github.com/moby/moby/pull/50504) - Go SDK: deprecate profiles package which got migrated to `github.com/moby/profiles`. [moby/moby#50481](https://github.com/moby/moby/pull/50481)