Skip to content

Instantly share code, notes, and snippets.

@skanehira
Created August 28, 2020 13:55
Show Gist options
  • Save skanehira/7a8b39c8fb823427136c18e13837c5c4 to your computer and use it in GitHub Desktop.
Save skanehira/7a8b39c8fb823427136c18e13837c5c4 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"log"
"os"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
streamer "github.com/skanehira/docker-streamer"
)
func main() {
os.Setenv("DOCKER_API_VERSION", "1.40")
cli, err := client.NewEnvClient()
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
response, err := cli.ContainerExecCreate(ctx, "golang", types.ExecConfig{
Tty: true,
AttachStdin: true,
AttachStderr: true,
AttachStdout: true,
Cmd: []string{"bash"},
})
if err != nil {
log.Fatal(err)
}
execID := response.ID
if execID == "" {
log.Fatalf("empty exec id")
}
s := streamer.New()
if err := s.Stream(ctx, cli, execID); err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment