Skip to content

Commit 20aa667

Browse files
authored
Merge pull request #658 from doringeman/docker-host
feat: add SSH remote host support via -H flag
2 parents cd24a2a + 2ba9de2 commit 20aa667

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

cmd/cli/desktop/context.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/containerd/errdefs"
1515
"github.com/docker/cli/cli/command"
16+
"github.com/docker/cli/cli/connhelper"
1617
"github.com/docker/cli/cli/context/docker"
1718
"github.com/docker/docker/api/types/container"
1819
clientpkg "github.com/docker/docker/client"
@@ -83,11 +84,25 @@ func DockerClientForContext(cli *command.DockerCli, name string) (*clientpkg.Cli
8384
if err != nil {
8485
return nil, fmt.Errorf("unable to determine context endpoint: %w", err)
8586
}
86-
return clientpkg.NewClientWithOpts(
87+
88+
opts := []clientpkg.Opt{
8789
clientpkg.FromEnv,
88-
clientpkg.WithHost(endpoint.Host),
8990
clientpkg.WithAPIVersionNegotiation(),
90-
)
91+
clientpkg.WithHost(endpoint.Host),
92+
}
93+
94+
helper, err := connhelper.GetConnectionHelper(endpoint.Host)
95+
if err != nil {
96+
return nil, fmt.Errorf("unable to get SSH connection helper: %w", err)
97+
}
98+
if helper != nil {
99+
opts = append(opts,
100+
clientpkg.WithHost(helper.Host),
101+
clientpkg.WithDialContext(helper.Dialer),
102+
)
103+
}
104+
105+
return clientpkg.NewClientWithOpts(opts...)
91106
}
92107

93108
// ModelRunnerContext encodes the operational context of a Model CLI command and

0 commit comments

Comments
 (0)