Skip to content

Commit 63ea976

Browse files
committed
FIX docker-archive-public#1858 Add engine port
Added flag `--generic-engine-port` to `generic` drive in order to specify other port than `2376` on Docker engine. Updated `generic` driver documentation. Signed-off-by: Tiago Pires <tandrepires@gmail.com>
1 parent ccc5fe6 commit 63ea976

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

docs/drivers/generic.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ as a sudoer with `NOPASSWD`. See https://help.ubuntu.com/community/Sudoers.
6262

6363
### Options
6464

65+
- `--generic-engine-port`: Port to use for Docker Daemon (Note: This flag will not work with boot2docker).
6566
- `--generic-ip-address`: **required** IP Address of host.
6667
- `--generic-ssh-key`: Path to the SSH user private key.
6768
- `--generic-ssh-user`: SSH username used to connect.
@@ -73,6 +74,7 @@ Environment variables and default values:
7374

7475
| CLI option | Environment variable | Default |
7576
| -------------------------- | -------------------- | ------------------------- |
77+
| `--generic-engine-port` | `GENERIC_ENGINE_PORT`| `2376` |
7678
| **`--generic-ip-address`** | `GENERIC_IP_ADDRESS` | - |
7779
| `--generic-ssh-key` | `GENERIC_SSH_KEY` | _(defers to `ssh-agent`)_ |
7880
| `--generic-ssh-user` | `GENERIC_SSH_USER` | `root` |

drivers/generic/generic.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/docker/machine/libmachine/drivers"
12+
"github.com/docker/machine/libmachine/engine"
1213
"github.com/docker/machine/libmachine/log"
1314
"github.com/docker/machine/libmachine/mcnflag"
1415
"github.com/docker/machine/libmachine/mcnutils"
@@ -17,7 +18,8 @@ import (
1718

1819
type Driver struct {
1920
*drivers.BaseDriver
20-
SSHKey string
21+
EnginePort int
22+
SSHKey string
2123
}
2224

2325
const (
@@ -28,6 +30,12 @@ const (
2830
// "docker hosts create"
2931
func (d *Driver) GetCreateFlags() []mcnflag.Flag {
3032
return []mcnflag.Flag{
33+
mcnflag.IntFlag{
34+
Name: "generic-engine-port",
35+
Usage: "Docker engine port",
36+
Value: engine.DefaultPort,
37+
EnvVar: "GENERIC_ENGINE_PORT",
38+
},
3139
mcnflag.StringFlag{
3240
Name: "generic-ip-address",
3341
Usage: "IP Address of machine",
@@ -57,6 +65,7 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
5765
// NewDriver creates and returns a new instance of the driver
5866
func NewDriver(hostName, storePath string) drivers.Driver {
5967
return &Driver{
68+
EnginePort: engine.DefaultPort,
6069
BaseDriver: &drivers.BaseDriver{
6170
MachineName: hostName,
6271
StorePath: storePath,
@@ -89,6 +98,7 @@ func (d *Driver) GetSSHKeyPath() string {
8998
}
9099

91100
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
101+
d.EnginePort = flags.Int("generic-engine-port")
92102
d.IPAddress = flags.String("generic-ip-address")
93103
d.SSHUser = flags.String("generic-ssh-user")
94104
d.SSHKey = flags.String("generic-ssh-key")
@@ -142,7 +152,7 @@ func (d *Driver) GetURL() (string, error) {
142152
return "", err
143153
}
144154

145-
return fmt.Sprintf("tcp://%s", net.JoinHostPort(ip, "2376")), nil
155+
return fmt.Sprintf("tcp://%s", net.JoinHostPort(ip, strconv.Itoa(d.EnginePort))), nil
146156
}
147157

148158
func (d *Driver) GetState() (state.State, error) {

drivers/generic/generic_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ func TestSetConfigFromFlags(t *testing.T) {
1212

1313
checkFlags := &drivers.CheckDriverOptions{
1414
FlagsValues: map[string]interface{}{
15-
"generic-ip-address": "localhost",
16-
"generic-ssh-key": "path",
15+
"generic-engine-port": "3000",
16+
"generic-ip-address": "localhost",
17+
"generic-ssh-key": "path",
1718
},
1819
CreateFlags: driver.GetCreateFlags(),
1920
}

libmachine/provision/configure_swarm.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package provision
33
import (
44
"fmt"
55
"net/url"
6+
"strconv"
67
"strings"
78

89
"github.com/docker/machine/libmachine/auth"
@@ -30,15 +31,30 @@ func configureSwarm(p Provisioner, swarmOptions swarm.Options, authOptions auth.
3031
return err
3132
}
3233

33-
parts := strings.Split(u.Host, ":")
34+
enginePort := engine.DefaultPort
35+
engineURL, err := p.GetDriver().GetURL()
36+
if err != nil {
37+
return err
38+
}
39+
40+
parts := strings.Split(engineURL, ":")
41+
if len(parts) == 3 {
42+
dPort, err := strconv.Atoi(parts[2])
43+
if err != nil {
44+
return err
45+
}
46+
enginePort = dPort
47+
}
48+
49+
parts = strings.Split(u.Host, ":")
3450
port := parts[1]
3551

3652
dockerDir := p.GetDockerOptionsDir()
3753
dockerHost := &mcndockerclient.RemoteDocker{
38-
HostURL: fmt.Sprintf("tcp://%s:%d", ip, engine.DefaultPort),
54+
HostURL: fmt.Sprintf("tcp://%s:%d", ip, enginePort),
3955
AuthOption: &authOptions,
4056
}
41-
advertiseInfo := fmt.Sprintf("%s:%d", ip, engine.DefaultPort)
57+
advertiseInfo := fmt.Sprintf("%s:%d", ip, enginePort)
4258

4359
if swarmOptions.Master {
4460
advertiseMasterInfo := fmt.Sprintf("%s:%s", ip, "3376")

0 commit comments

Comments
 (0)