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.shwith 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
vdiformat.VBoxManage convertdd ~/.docker/machine/cache/boot2docker.iso ~/.docker/machine/cache/boot2docker.vdi --format VDIThis step is required since VirtualBox does not include
.isofiles in.ovaarchives 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
Advancedand open thePort Forwardingdialog - 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 > Storageand- delete the
Optical Drivein the Storage tree - select
Add Hard Disk>Choose existing diskand choose the vdi file created above (~/.docker/machine/cache/boot2docker.vdi).
- delete the
- use
File > Export Applianceto export the virtual machine
Leave a comment