Skip to content

Commit 34db311

Browse files
committed
engine: update go sdk examples to use new moby/moby/client module
Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
1 parent 8cc6a0c commit 34db311

File tree

2 files changed

+143
-149
lines changed

2 files changed

+143
-149
lines changed

content/reference/api/engine/sdk/_index.md

Lines changed: 75 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,18 @@ installed and coexist together.
2626
### Go SDK
2727

2828
```console
29-
$ go get github.com/docker/docker/client
29+
$ go get github.com/moby/moby/client
3030
```
3131

3232
The client requires a recent version of Go. Run `go version` and ensure that you're running a currently supported version of Go.
3333

34-
35-
For more information, see [Docker Engine Go SDK reference](https://godoc.org/github.com/docker/docker/client).
34+
For more information, see [Go client reference](https://pkg.go.dev/github.com/moby/moby/client).
3635

3736
### Python SDK
3837

3938
- Recommended: Run `pip install docker`.
4039

4140
- If you can't use `pip`:
42-
4341
1. [Download the package directly](https://pypi.python.org/pypi/docker/).
4442
2. Extract it and change to the extracted directory.
4543
3. Run `python setup.py install`.
@@ -84,53 +82,54 @@ import (
8482
"io"
8583
"os"
8684

87-
"github.com/docker/docker/api/types/container"
88-
"github.com/docker/docker/api/types/image"
89-
"github.com/docker/docker/client"
90-
"github.com/docker/docker/pkg/stdcopy"
85+
"github.com/moby/moby/api/pkg/stdcopy"
86+
"github.com/moby/moby/api/types/container"
87+
"github.com/moby/moby/client"
9188
)
9289

9390
func main() {
94-
ctx := context.Background()
95-
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
96-
if err != nil {
97-
panic(err)
98-
}
99-
defer cli.Close()
100-
101-
reader, err := cli.ImagePull(ctx, "docker.io/library/alpine", image.PullOptions{})
102-
if err != nil {
103-
panic(err)
104-
}
105-
io.Copy(os.Stdout, reader)
106-
107-
resp, err := cli.ContainerCreate(ctx, &container.Config{
108-
Image: "alpine",
109-
Cmd: []string{"echo", "hello world"},
110-
}, nil, nil, nil, "")
111-
if err != nil {
112-
panic(err)
113-
}
114-
115-
if err := cli.ContainerStart(ctx, resp.ID, container.StartOptions{}); err != nil {
116-
panic(err)
117-
}
118-
119-
statusCh, errCh := cli.ContainerWait(ctx, resp.ID, container.WaitConditionNotRunning)
120-
select {
121-
case err := <-errCh:
122-
if err != nil {
123-
panic(err)
124-
}
125-
case <-statusCh:
126-
}
127-
128-
out, err := cli.ContainerLogs(ctx, resp.ID, container.LogsOptions{ShowStdout: true})
129-
if err != nil {
130-
panic(err)
131-
}
132-
133-
stdcopy.StdCopy(os.Stdout, os.Stderr, out)
91+
ctx := context.Background()
92+
apiClient, err := client.New(client.FromEnv)
93+
if err != nil {
94+
panic(err)
95+
}
96+
defer apiClient.Close()
97+
98+
reader, err := apiClient.ImagePull(ctx, "docker.io/library/alpine", client.ImagePullOptions{})
99+
if err != nil {
100+
panic(err)
101+
}
102+
io.Copy(os.Stdout, reader)
103+
104+
resp, err := apiClient.ContainerCreate(ctx, client.ContainerCreateOptions{
105+
Image: "alpine",
106+
Config: &container.Config{
107+
Cmd: []string{"echo", "hello world"},
108+
},
109+
})
110+
if err != nil {
111+
panic(err)
112+
}
113+
114+
if _, err := apiClient.ContainerStart(ctx, resp.ID, client.ContainerStartOptions{}); err != nil {
115+
panic(err)
116+
}
117+
118+
wait := apiClient.ContainerWait(ctx, resp.ID, client.ContainerWaitOptions{})
119+
select {
120+
case err := <-wait.Error:
121+
if err != nil {
122+
panic(err)
123+
}
124+
case <-wait.Result:
125+
}
126+
127+
out, err := apiClient.ContainerLogs(ctx, resp.ID, client.ContainerLogsOptions{ShowStdout: true})
128+
if err != nil {
129+
panic(err)
130+
}
131+
132+
stdcopy.StdCopy(os.Stdout, os.Stderr, out)
134133
}
135134
```
136135

@@ -184,31 +183,31 @@ There are a number of community supported libraries available for other
184183
languages. They haven't been tested by Docker, so if you run into any issues,
185184
file them with the library maintainers.
186185

187-
| Language | Library |
188-
|:----------------------|:----------------------------------------------------------------------------|
189-
| C | [libdocker](https://github.com/danielsuo/libdocker) |
190-
| C# | [Docker.DotNet](https://github.com/ahmetalpbalkan/Docker.DotNet) |
191-
| C++ | [lasote/docker_client](https://github.com/lasote/docker_client) |
192-
| Clojure | [clj-docker-client](https://github.com/into-docker/clj-docker-client) |
193-
| Clojure | [contajners](https://github.com/lispyclouds/contajners) |
194-
| Dart | [bwu_docker](https://github.com/bwu-dart/bwu_docker) |
195-
| Erlang | [erldocker](https://github.com/proger/erldocker) |
196-
| Gradle | [gradle-docker-plugin](https://github.com/gesellix/gradle-docker-plugin) |
197-
| Groovy | [docker-client](https://github.com/gesellix/docker-client) |
198-
| Haskell | [docker-hs](https://github.com/denibertovic/docker-hs) |
199-
| Java | [docker-client](https://github.com/spotify/docker-client) |
200-
| Java | [docker-java](https://github.com/docker-java/docker-java) |
201-
| Java | [docker-java-api](https://github.com/amihaiemil/docker-java-api) |
202-
| Java | [jocker](https://github.com/ndeloof/jocker) |
203-
| NodeJS | [dockerode](https://github.com/apocas/dockerode) |
204-
| NodeJS | [harbor-master](https://github.com/arhea/harbor-master) |
205-
| NodeJS | [the-moby-effect](https://github.com/leonitousconforti/the-moby-effect) |
206-
| Perl | [Eixo::Docker](https://github.com/alambike/eixo-docker) |
207-
| PHP | [Docker-PHP](https://github.com/docker-php/docker-php) |
208-
| Ruby | [docker-api](https://github.com/swipely/docker-api) |
209-
| Rust | [bollard](https://github.com/fussybeaver/bollard) |
210-
| Rust | [docker-rust](https://github.com/abh1nav/docker-rust) |
211-
| Rust | [shiplift](https://github.com/softprops/shiplift) |
212-
| Scala | [tugboat](https://github.com/softprops/tugboat) |
213-
| Scala | [reactive-docker](https://github.com/almoehi/reactive-docker) |
214-
| Swift | [docker-client-swift](https://github.com/valeriomazzeo/docker-client-swift) |
186+
| Language | Library |
187+
| :------- | :-------------------------------------------------------------------------- |
188+
| C | [libdocker](https://github.com/danielsuo/libdocker) |
189+
| C# | [Docker.DotNet](https://github.com/ahmetalpbalkan/Docker.DotNet) |
190+
| C++ | [lasote/docker_client](https://github.com/lasote/docker_client) |
191+
| Clojure | [clj-docker-client](https://github.com/into-docker/clj-docker-client) |
192+
| Clojure | [contajners](https://github.com/lispyclouds/contajners) |
193+
| Dart | [bwu_docker](https://github.com/bwu-dart/bwu_docker) |
194+
| Erlang | [erldocker](https://github.com/proger/erldocker) |
195+
| Gradle | [gradle-docker-plugin](https://github.com/gesellix/gradle-docker-plugin) |
196+
| Groovy | [docker-client](https://github.com/gesellix/docker-client) |
197+
| Haskell | [docker-hs](https://github.com/denibertovic/docker-hs) |
198+
| Java | [docker-client](https://github.com/spotify/docker-client) |
199+
| Java | [docker-java](https://github.com/docker-java/docker-java) |
200+
| Java | [docker-java-api](https://github.com/amihaiemil/docker-java-api) |
201+
| Java | [jocker](https://github.com/ndeloof/jocker) |
202+
| NodeJS | [dockerode](https://github.com/apocas/dockerode) |
203+
| NodeJS | [harbor-master](https://github.com/arhea/harbor-master) |
204+
| NodeJS | [the-moby-effect](https://github.com/leonitousconforti/the-moby-effect) |
205+
| Perl | [Eixo::Docker](https://github.com/alambike/eixo-docker) |
206+
| PHP | [Docker-PHP](https://github.com/docker-php/docker-php) |
207+
| Ruby | [docker-api](https://github.com/swipely/docker-api) |
208+
| Rust | [bollard](https://github.com/fussybeaver/bollard) |
209+
| Rust | [docker-rust](https://github.com/abh1nav/docker-rust) |
210+
| Rust | [shiplift](https://github.com/softprops/shiplift) |
211+
| Scala | [tugboat](https://github.com/softprops/tugboat) |
212+
| Scala | [reactive-docker](https://github.com/almoehi/reactive-docker) |
213+
| Swift | [docker-client-swift](https://github.com/valeriomazzeo/docker-client-swift) |

0 commit comments

Comments
 (0)