Creating cross-platform portable Virtual Machines with Docker
- create a docker virtualbox machine and connect to it
docker-machine create dbms eval "$(docker-machine env dbms)"
- build the docker image
docker build --rm --tag albert/dbms:current .
- modify the machine to start the docker image at startup
docker-machine ssh dbms vi /mnt/sda1/var/lib/boot2docker/bootlocal.sh
with content
#!/bin/sh # wait until docker has been started while ! docker version; do sleep 1; done docker run --network=host albert/dbms:current
-
make the startup script executable with
chmod a+x /mnt/sda1/var/lib/boot2docker/bootlocal.sh
. - convert the boot2docker iso file to the
vdi
format.VBoxManage convertdd ~/.docker/machine/cache/boot2docker.iso ~/.docker/machine/cache/boot2docker.vdi --format VDI
This step is required since VirtualBox does not include
.iso
files in.ova
archives and without the file your machine does not boot. - Setup port forwarding, to expose services to localhost:
- Open the VM network settings in VirtualBox
- Choose
Advanced
and open thePort Forwarding
dialog - Setup the relevant port forwarding rules with host IP
127.0.0.1
- finalize and export
- open the created virtual machine in VirtualBox
- open the machine’s
Settings > Storage
and- delete the
Optical Drive
in the Storage tree - select
Add Hard Disk
>Choose existing disk
and choose the vdi file created above (~/.docker/machine/cache/boot2docker.vdi
).
- delete the
- use
File > Export Appliance
to export the virtual machine
Leave a comment