Skip to content
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

fix: failed to run docker.go #236

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions _examples/ssh-docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io"
"log"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/stdcopy"
Expand Down Expand Up @@ -42,21 +41,25 @@ func main() {
}

func dockerRun(cfg *container.Config, sess ssh.Session) (status int64, cleanup func(), err error) {
docker, err := client.NewEnvClient()
docker, err := client.NewClientWithOpts()
if err != nil {
panic(err)
}
status = 255
cleanup = func() {}
ctx := context.Background()
res, err := docker.ContainerCreate(ctx, cfg, nil, nil, "")
res, err := docker.ContainerCreate(ctx, cfg, nil, nil, nil, "")
if err != nil {
return
}
cleanup = func() {
docker.ContainerRemove(ctx, res.ID, types.ContainerRemoveOptions{})
docker.ContainerRemove(
ctx,
res.ID,
container.RemoveOptions{},
)
}
opts := types.ContainerAttachOptions{
opts := container.AttachOptions{
Stdin: cfg.AttachStdin,
Stdout: cfg.AttachStdout,
Stderr: cfg.AttachStderr,
Expand All @@ -67,7 +70,7 @@ func dockerRun(cfg *container.Config, sess ssh.Session) (status int64, cleanup f
return
}
cleanup = func() {
docker.ContainerRemove(ctx, res.ID, types.ContainerRemoveOptions{})
docker.ContainerRemove(ctx, res.ID, container.RemoveOptions{})
stream.Close()
}

Expand All @@ -88,15 +91,15 @@ func dockerRun(cfg *container.Config, sess ssh.Session) (status int64, cleanup f
io.Copy(stream.Conn, sess)
}()

err = docker.ContainerStart(ctx, res.ID, types.ContainerStartOptions{})
err = docker.ContainerStart(ctx, res.ID, container.StartOptions{})
if err != nil {
return
}
if cfg.Tty {
_, winCh, _ := sess.Pty()
go func() {
for win := range winCh {
err := docker.ContainerResize(ctx, res.ID, types.ResizeOptions{
err := docker.ContainerResize(ctx, res.ID, container.ResizeOptions{
Height: uint(win.Height),
Width: uint(win.Width),
})
Expand Down