Skip to content

Commit f4201b9

Browse files
authored
Merge pull request #4073 from panekj/feat/ssh-socket-path
connhelper: Allow socket path when using SSH
2 parents 9f15ba0 + 25ebf0e commit f4201b9

4 files changed

Lines changed: 13 additions & 6 deletions

File tree

cli/connhelper/connhelper.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ func getConnectionHelper(daemonURL string, sshFlags []string) (*ConnectionHelper
4747
}
4848
return &ConnectionHelper{
4949
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
50-
return commandconn.New(ctx, "ssh", append(sshFlags, sp.Args("docker", "system", "dial-stdio")...)...)
50+
args := []string{"docker"}
51+
if sp.Path != "" {
52+
args = append(args, "--host", "unix://"+sp.Path)
53+
}
54+
args = append(args, "system", "dial-stdio")
55+
return commandconn.New(ctx, "ssh", append(sshFlags, sp.Args(args...)...)...)
5156
},
5257
Host: "http://docker.example.com",
5358
}, nil

cli/connhelper/ssh/ssh.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ func ParseURL(daemonURL string) (*Spec, error) {
3030
return nil, errors.Errorf("no host specified")
3131
}
3232
sp.Port = u.Port()
33-
if u.Path != "" {
34-
return nil, errors.Errorf("extra path after the host: %q", u.Path)
35-
}
33+
sp.Path = u.Path
3634
if u.RawQuery != "" {
3735
return nil, errors.Errorf("extra query after the host: %q", u.RawQuery)
3836
}
@@ -47,6 +45,7 @@ type Spec struct {
4745
User string
4846
Host string
4947
Port string
48+
Path string
5049
}
5150

5251
// Args returns args except "ssh" itself combined with optional additional command args

cli/connhelper/ssh/ssh_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ func TestParseURL(t *testing.T) {
3232
expectedError: "plain-text password is not supported",
3333
},
3434
{
35-
url: "ssh://foo/bar",
36-
expectedError: `extra path after the host: "/bar"`,
35+
url: "ssh://foo/bar",
36+
expectedArgs: []string{
37+
"--", "foo",
38+
},
3739
},
3840
{
3941
url: "ssh://foo?bar",

docs/reference/commandline/dockerd.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ precedence over `HTTP_PROXY`.
242242
The Docker client supports connecting to a remote daemon via SSH:
243243

244244
```console
245+
$ docker -H ssh://me@example.com:22/var/run/docker.sock ps
245246
$ docker -H ssh://me@example.com:22 ps
246247
$ docker -H ssh://me@example.com ps
247248
$ docker -H ssh://example.com ps

0 commit comments

Comments
 (0)