Skip to content
This repository was archived by the owner on Feb 27, 2018. It is now read-only.

Commit 749e187

Browse files
Sven DowideitSven Dowideit
authored andcommitted
Merge pull request #134 from SvenDowideit/use-actual-vbox-ports
Once the Vm has been created, use the VBox setting
2 parents 198decb + 60313a3 commit 749e187

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

cmds.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func cmdUp() int {
224224
}
225225

226226
logf("Waiting for SSH server to start...")
227-
addr := fmt.Sprintf("localhost:%d", B2D.SSHPort)
227+
addr := fmt.Sprintf("localhost:%d", m.SSHPort)
228228
const n = 10
229229
// Try to connect to the SSH 10 times at 3 sec interval before giving up.
230230
if err := read(addr, n, 3*time.Second); err != nil {
@@ -241,9 +241,9 @@ func cmdUp() int {
241241
logf("to SSH into the VM instead.")
242242
default:
243243
// Check if $DOCKER_HOST ENV var is properly configured.
244-
if os.Getenv("DOCKER_HOST") != fmt.Sprintf("tcp://localhost:%d", B2D.DockerPort) {
244+
if os.Getenv("DOCKER_HOST") != fmt.Sprintf("tcp://localhost:%d", m.DockerPort) {
245245
logf("To connect the Docker client to the Docker daemon, please set:")
246-
logf(" export DOCKER_HOST=tcp://localhost:%d", B2D.DockerPort)
246+
logf(" export DOCKER_HOST=tcp://localhost:%d", m.DockerPort)
247247
}
248248
}
249249
return 0
@@ -400,7 +400,7 @@ func cmdSSH() int {
400400
if err := cmd(B2D.SSH,
401401
"-o", "StrictHostKeyChecking=no",
402402
"-o", "UserKnownHostsFile=/dev/null",
403-
"-p", fmt.Sprintf("%d", B2D.SSHPort),
403+
"-p", fmt.Sprintf("%d", m.SSHPort),
404404
"-i", B2D.SSHKey,
405405
"docker@localhost",
406406
strings.Join(os.Args[i:], " "),

virtualbox/machine.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ type Machine struct {
6666
OSType string
6767
Flag Flag
6868
BootOrder []string // max 4 slots, each in {none|floppy|dvd|disk|net}
69+
DockerPort uint
70+
SSHPort uint
6971
}
7072

7173
// Refresh reloads the machine information.
@@ -233,6 +235,22 @@ func GetMachine(id string) (*Machine, error) {
233235
case "CfgFile":
234236
m.CfgFile = val
235237
m.BaseFolder = filepath.Dir(val)
238+
case "Forwarding(0)":
239+
// Forwarding(0)="docker,tcp,127.0.0.1,5555,,4243"
240+
vals := strings.Split(val, ",")
241+
n, err := strconv.ParseUint(vals[3], 10, 32)
242+
if err != nil {
243+
return nil, err
244+
}
245+
m.DockerPort = uint(n)
246+
case "Forwarding(1)":
247+
// Forwarding(1)="ssh,tcp,127.0.0.1,2222,,22"
248+
vals := strings.Split(val, ",")
249+
n, err := strconv.ParseUint(vals[3], 10, 32)
250+
if err != nil {
251+
return nil, err
252+
}
253+
m.SSHPort = uint(n)
236254
}
237255
}
238256
if err := s.Err(); err != nil {

0 commit comments

Comments
 (0)