-
Notifications
You must be signed in to change notification settings - Fork 2k
VirtualBox: enable ability to import b2d instances #979
Changes from all commits
576951e
7a4e16e
a01322f
33eab99
8f66be1
e9491d2
d881aa8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
This guide explains migrating from the Boot2Docker CLI to Docker Machine. | ||
|
||
This guide assumes basic knowledge of the Boot2Docker CLI and Docker Machine. If you are not familiar, please review those docs prior to migrating. | ||
|
||
There are a few differences between the Boot2Docker CLI commands and Machine. Please review the table below for the Boot2Docker command and the corresponding Machine command. You can also see details on Machine commands in the official [Docker Machine Docs](http://docs.docker.com/machine/#subcommands). | ||
|
||
# Migrating | ||
|
||
In order to migrate a Boot2Docker VM to Docker Machine, you must have Docker Machine installed. If you do not have Docker Machine, please see the [install docs](http://docs.docker.com/machine/#installation) before proceeding. | ||
|
||
> Note: when migrating to Docker Machine, this will also update Docker to the latest stable version | ||
|
||
To migrate a Boot2Docker VM, run the following command where `<boot2docker-vm-name>` is the name of your Boot2Docker VM and `<new-machine-name>` is the name of the new Machine (i.e. `dev`): | ||
|
||
> To get the name of your Boot2Docker VM, use the `boot2docker config` command. Default: `boot2docker-vm`. | ||
|
||
``` | ||
docker-machine create -d virtualbox --virtualbox-import-boot2docker-vm <boot2docker-vm-name> <new-machine-name> | ||
``` | ||
|
||
> Note: this will stop the Boot2Docker VM in order to safely copy the virtual disk | ||
|
||
You should see output similar to the following: | ||
|
||
``` | ||
$> docker-machine create -d virtualbox --virtualbox-import-boot2docker-vm boot2docker-vm dev | ||
INFO[0000] Creating VirtualBox VM... | ||
INFO[0001] Starting VirtualBox VM... | ||
INFO[0001] Waiting for VM to start... | ||
INFO[0035] "dev" has been created and is now the active machine. | ||
INFO[0035] To point your Docker client at it, run this in your shell: eval "$(docker-machine env dev)" | ||
``` | ||
|
||
You now should have a Machine that contains all of the Docker data from the Boot2Docker VM. See the Docker Machine [usage docs](http://docs.docker.com/machine/#getting-started-with-docker-machine-using-a-local-vm) for details on working with Machine. | ||
|
||
# Cleanup | ||
When migrating a Boot2Docker VM to Docker Machine the Boot2Docker VM is left intact. Once you have verified that all of your Docker data (containers, images, etc) are in the new Machine, you can remove the Boot2Docker VM using `boot2docker delete`. | ||
|
||
# Command Comparison | ||
|
||
| boot2docker cli | machine | machine description | | ||
|----|----|----| | ||
| init | create | creates a new docker host | | ||
| up | start | starts a stopped machine | | ||
| ssh | ssh | runs a command or interactive ssh session on the machine | | ||
| save | - | n/a | | ||
| down | stop | stops a running machine | | ||
| poweroff | stop | stops a running machine | | ||
| reset | restart | restarts a running machine | | ||
| config | inspect (*) | shows details about machine | | ||
| status | ls (**) | shows a list of all machines | | ||
| info | inspect (*) | shows details about machine | | ||
| ip | url (***) | shows the Docker URL for the machine | | ||
| shellinit | env | shows the environment configuration needed to configure the Docker CLI for the machine | | ||
| delete | rm | removes a machine | | ||
| download | - | | | ||
| upgrade | upgrade | upgrades Docker on the machine to the latest stable release | | ||
|
||
|
||
\* provides similar functionality but not exact | ||
|
||
** `ls` will show all machines including their status | ||
|
||
** the `url` command reports the entire Docker URL including the IP / Hostname: | ||
``` | ||
``` | ||
``` | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package virtualbox | ||
|
||
import ( | ||
"bufio" | ||
"io" | ||
"strings" | ||
) | ||
|
||
type VirtualDisk struct { | ||
UUID string | ||
Path string | ||
} | ||
|
||
func parseDiskInfo(r io.Reader) (*VirtualDisk, error) { | ||
s := bufio.NewScanner(r) | ||
disk := &VirtualDisk{} | ||
for s.Scan() { | ||
line := s.Text() | ||
if line == "" { | ||
continue | ||
} | ||
res := reEqualQuoteLine.FindStringSubmatch(line) | ||
if res == nil { | ||
continue | ||
} | ||
key, val := res[1], res[2] | ||
switch key { | ||
case "SATA-1-0": | ||
disk.Path = val | ||
case "SATA-ImageUUID-1-0": | ||
disk.UUID = val | ||
} | ||
} | ||
if err := s.Err(); err != nil { | ||
return nil, err | ||
} | ||
return disk, nil | ||
} | ||
|
||
func getVMDiskInfo(name string) (*VirtualDisk, error) { | ||
out, err := vbmOut("showvminfo", name, "--machinereadable") | ||
if err != nil { | ||
return nil, err | ||
} | ||
r := strings.NewReader(out) | ||
return parseDiskInfo(r) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package virtualbox | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
var ( | ||
testDiskInfoText = ` | ||
storagecontrollerbootable0="on" | ||
"SATA-0-0"="/home/ehazlett/.boot2docker/boot2docker.iso" | ||
"SATA-IsEjected"="off" | ||
"SATA-1-0"="/home/ehazlett/vm/test/disk.vmdk" | ||
"SATA-ImageUUID-1-0"="12345-abcdefg" | ||
"SATA-2-0"="none" | ||
nic1="nat" | ||
` | ||
) | ||
|
||
func TestVMDiskInfo(t *testing.T) { | ||
r := strings.NewReader(testDiskInfoText) | ||
disk, err := parseDiskInfo(r) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
diskPath := "/home/ehazlett/vm/test/disk.vmdk" | ||
diskUUID := "12345-abcdefg" | ||
if disk.Path != diskPath { | ||
t.Fatalf("expected disk path %s", diskPath) | ||
} | ||
|
||
if disk.UUID != diskUUID { | ||
t.Fatalf("expected disk uuid %s", diskUUID) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package virtualbox | ||
|
||
import ( | ||
"bufio" | ||
"io" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
type VirtualBoxVM struct { | ||
CPUs int | ||
Memory int | ||
} | ||
|
||
func parseVMInfo(r io.Reader) (*VirtualBoxVM, error) { | ||
s := bufio.NewScanner(r) | ||
vm := &VirtualBoxVM{} | ||
for s.Scan() { | ||
line := s.Text() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you move this little block into its own function please? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what you mean here. The scanning? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The bit after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but then we would have to pass the ref to |
||
if line == "" { | ||
continue | ||
} | ||
res := reEqualLine.FindStringSubmatch(line) | ||
if res == nil { | ||
continue | ||
} | ||
switch key, val := res[1], res[2]; key { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I think I'd prefer separate lines for the assignment and the switch here for clarity ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok works for me. We should change it in the original too -- that's how it is to find the network details too. |
||
case "cpus": | ||
v, err := strconv.Atoi(val) | ||
if err != nil { | ||
return nil, err | ||
} | ||
vm.CPUs = v | ||
case "memory": | ||
v, err := strconv.Atoi(val) | ||
if err != nil { | ||
return nil, err | ||
} | ||
vm.Memory = v | ||
} | ||
} | ||
if err := s.Err(); err != nil { | ||
return nil, err | ||
} | ||
return vm, nil | ||
} | ||
|
||
func getVMInfo(name string) (*VirtualBoxVM, error) { | ||
out, err := vbmOut("showvminfo", name, "--machinereadable") | ||
if err != nil { | ||
return nil, err | ||
} | ||
r := strings.NewReader(out) | ||
return parseVMInfo(r) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package virtualbox | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
var ( | ||
testVMInfoText = ` | ||
storagecontrollerbootable0="on" | ||
memory=1024 | ||
cpus=2 | ||
"SATA-0-0"="/home/ehazlett/.boot2docker/boot2docker.iso" | ||
"SATA-IsEjected"="off" | ||
"SATA-1-0"="/home/ehazlett/vm/test/disk.vmdk" | ||
"SATA-ImageUUID-1-0"="12345-abcdefg" | ||
"SATA-2-0"="none" | ||
nic1="nat" | ||
` | ||
) | ||
|
||
func TestVMInfo(t *testing.T) { | ||
r := strings.NewReader(testVMInfoText) | ||
vm, err := parseVMInfo(r) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
vmCPUs := 2 | ||
vmMemory := 1024 | ||
if vm.CPUs != vmCPUs { | ||
t.Fatalf("expected %d cpus; received %d", vmCPUs, vm.CPUs) | ||
} | ||
|
||
if vm.Memory != vmMemory { | ||
t.Fatalf("expected memory %d; received %d", vmMemory, vm.Memory) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I keep thinking that maybe we should default this value to
boot2docker-vm
, since that's by far the most common name and I have a feeling users will run this flag without args expecting it to "just work".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, I'd certainly expect that myself -- I don't know that's it's very common for users to actually name their boot2docker VMs (even though it's supported to do so)