-
Notifications
You must be signed in to change notification settings - Fork 8.1k
update the demo code #20530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update the demo code #20530
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,54 +81,55 @@ import ( | |
| "io" | ||
| "os" | ||
|
|
||
| "github.com/docker/docker/api/types" | ||
| "github.com/docker/docker/api/types/container" | ||
| "github.com/docker/docker/api/types/image" | ||
| "github.com/docker/docker/api/types/image" | ||
| "github.com/docker/docker/client" | ||
| "github.com/docker/docker/pkg/stdcopy" | ||
| ) | ||
|
|
||
| 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, types.ContainerStartOptions{}); 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, types.ContainerLogsOptions{ShowStdout: true}) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| stdcopy.StdCopy(os.Stdout, os.Stderr, out) | ||
| ctx := context.Background() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For others reviewing; the large number of lines changes is due to spaces -> tabs. Go uses tabs for indenting, but let me double-check with @dvdksn if there perhaps was a reason to use spaces for the docs (maybe for formatting reasons)? To review the changes with whitespace changes hidden, add |
||
| 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) | ||
| } | ||
| ``` | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.