Creating cross-platform portable Virtual Machines with Docker

1 minute read

  1. create a docker virtualbox machine and connect to it
    docker-machine create dbms
    eval "$(docker-machine env dbms)"
  2. build the docker image
    docker build --rm --tag albert/dbms:current .
  3. modify the machine to start the docker image at startup
    docker-machine ssh dbms
    vi /mnt/sda1/var/lib/boot2docker/

    with content

    # wait until docker has been started
    while ! docker version; do sleep 1; done
    docker run --network=host albert/dbms:current
  4. make the startup script executable with chmod a+x /mnt/sda1/var/lib/boot2docker/

  5. 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.

  6. Setup port forwarding, to expose services to localhost:
    • Open the VM network settings in VirtualBox
    • Choose Advanced and open the Port Forwarding dialog
    • Setup the relevant port forwarding rules with host IP
  7. 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).
    • use File > Export Appliance to export the virtual machine


Leave a comment