Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "context"
- "os"
- "github.com/docker/docker/api/types"
- "github.com/docker/docker/api/types/container"
- "github.com/docker/docker/client"
- "github.com/docker/docker/pkg/stdcopy"
- )
- func main() {
- ctx := context.Background()
- cli, err := client.NewClientWithOpts(client.FromEnv)
- if err != nil {
- panic(err)
- }
- cli.NegotiateAPIVersion(ctx)
- resp, err := cli.ContainerCreate(ctx, &container.Config{
- Image: "go-multi-stage",
- }, 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)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement