Skip to content
Closed
Show file tree
Hide file tree
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
16 changes: 9 additions & 7 deletions cli/connhelper/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,25 @@ func ParseURL(daemonURL string) (*Spec, error) {
if u.RawQuery != "" {
return nil, errors.Errorf("extra query after the host: %q", u.RawQuery)
}
if u.Fragment != "" {
return nil, errors.Errorf("extra fragment after the host: %q", u.Fragment)
}
sp.SSHConfig = u.Fragment
return &sp, err
}

// Spec of SSH URL
type Spec struct {
User string
Host string
Port string
Path string
User string
Host string
Port string
Path string
SSHConfig string
}

// Args returns args except "ssh" itself combined with optional additional command args
func (sp *Spec) Args(add ...string) []string {
var args []string
if sp.SSHConfig != "" {
args = append(args, "-F", sp.SSHConfig)
}
if sp.User != "" {
args = append(args, "-l", sp.User)
}
Expand Down
11 changes: 7 additions & 4 deletions cli/connhelper/ssh/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ func TestParseURL(t *testing.T) {
"--", "foo",
},
},
{
url: "ssh://foo#/path/to/ssh_config",
expectedArgs: []string{
"-F", "/path/to/ssh_config",
"--", "foo",
},
},
{
url: "ssh://me:passw0rd@foo",
expectedError: "plain-text password is not supported",
Expand All @@ -41,10 +48,6 @@ func TestParseURL(t *testing.T) {
url: "ssh://foo?bar",
expectedError: `extra query after the host: "bar"`,
},
{
url: "ssh://foo#bar",
expectedError: `extra fragment after the host: "bar"`,
},
{
url: "ssh://",
expectedError: "no host specified",
Expand Down
8 changes: 8 additions & 0 deletions docs/reference/commandline/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,14 @@ component to the end of the SSH address.
$ docker -H ssh://user@192.168.64.5/var/run/docker.sock ps
```

In addition, you can optionally specify an SSH config file by appending a
fragment component to the end of the SSH address (that is, behind a hash `#`).
The given file path is passed to SSH using the `ssh -F` option.

```console
$ docker -H ssh://user@192.168.64.5#/path/to/ssh_config ps
```

### Display help text

To list the help on any command just execute the command, followed by the
Expand Down
1 change: 1 addition & 0 deletions docs/reference/dockerd.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ precedence over `HTTP_PROXY`.
The Docker client supports connecting to a remote daemon via SSH:

```console
$ docker -H ssh://me@example.com:22/var/run/docker.sock#/path/to/ssh_config ps
$ 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 ps
Expand Down