mirror of https://github.com/docker/cli.git
connhelper: Allow socket path when using SSH
Signed-off-by: Jakub Panek <me@panekj.dev>
This commit is contained in:
parent
c549fd7360
commit
25ebf0ec9c
|
@ -47,7 +47,12 @@ func getConnectionHelper(daemonURL string, sshFlags []string) (*ConnectionHelper
|
||||||
}
|
}
|
||||||
return &ConnectionHelper{
|
return &ConnectionHelper{
|
||||||
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||||
return commandconn.New(ctx, "ssh", append(sshFlags, sp.Args("docker", "system", "dial-stdio")...)...)
|
args := []string{"docker"}
|
||||||
|
if sp.Path != "" {
|
||||||
|
args = append(args, "--host", "unix://"+sp.Path)
|
||||||
|
}
|
||||||
|
args = append(args, "system", "dial-stdio")
|
||||||
|
return commandconn.New(ctx, "ssh", append(sshFlags, sp.Args(args...)...)...)
|
||||||
},
|
},
|
||||||
Host: "http://docker.example.com",
|
Host: "http://docker.example.com",
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
@ -30,9 +30,7 @@ func ParseURL(daemonURL string) (*Spec, error) {
|
||||||
return nil, errors.Errorf("no host specified")
|
return nil, errors.Errorf("no host specified")
|
||||||
}
|
}
|
||||||
sp.Port = u.Port()
|
sp.Port = u.Port()
|
||||||
if u.Path != "" {
|
sp.Path = u.Path
|
||||||
return nil, errors.Errorf("extra path after the host: %q", u.Path)
|
|
||||||
}
|
|
||||||
if u.RawQuery != "" {
|
if u.RawQuery != "" {
|
||||||
return nil, errors.Errorf("extra query after the host: %q", u.RawQuery)
|
return nil, errors.Errorf("extra query after the host: %q", u.RawQuery)
|
||||||
}
|
}
|
||||||
|
@ -47,6 +45,7 @@ type Spec struct {
|
||||||
User string
|
User string
|
||||||
Host string
|
Host string
|
||||||
Port string
|
Port string
|
||||||
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Args returns args except "ssh" itself combined with optional additional command args
|
// Args returns args except "ssh" itself combined with optional additional command args
|
||||||
|
|
|
@ -33,7 +33,9 @@ func TestParseURL(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
url: "ssh://foo/bar",
|
url: "ssh://foo/bar",
|
||||||
expectedError: `extra path after the host: "/bar"`,
|
expectedArgs: []string{
|
||||||
|
"--", "foo",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
url: "ssh://foo?bar",
|
url: "ssh://foo?bar",
|
||||||
|
|
|
@ -213,6 +213,7 @@ precedence over `HTTP_PROXY`.
|
||||||
The Docker client supports connecting to a remote daemon via SSH:
|
The Docker client supports connecting to a remote daemon via SSH:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
|
$ docker -H ssh://me@example.com:22/var/run/docker.sock ps
|
||||||
$ docker -H ssh://me@example.com:22 ps
|
$ docker -H ssh://me@example.com:22 ps
|
||||||
$ docker -H ssh://me@example.com ps
|
$ docker -H ssh://me@example.com ps
|
||||||
$ docker -H ssh://example.com ps
|
$ docker -H ssh://example.com ps
|
||||||
|
|
Loading…
Reference in New Issue