Posted by & filed under DevOps, Docker.

Boot2docker is a lightweight linux virtual machine for running Docker on OS X and Windows, providing non-Linux users with easy access to the world of Linux containers. The lightweight VM comes in the form of a downloadable ISO which is then used to create the virtual machine. This means you can have more than one boot2docker VM for using different versions, Guest Additions, etc.

Our use case is particular to Guest Additions which is required to support shared folders on OS X. Because the current implementation of shared folders is temporary and it may come with some security implications, we don’t want to completely switch over to that version of boot2docker. Instead, we’ll create two profiles: the normal boot2docker, and boot2docker with Guest Additions.

First, we’ll download and install Boot2docker. Follow the directions here.

After Boot2docker has been installed, verify it’s up and running by doing the following:

> boot2docker ssh
                        ##        .
                  ## ## ##       ==
               ## ## ## ##      ===
           /""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
           \______ o          __/
             \    \        __/
              \____\______/
 _                 _   ____     _            _
| |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
boot2docker: 1.2.0
             3.16.1-config-file : e75396e - Fri Aug 22 06:45:30 UTC 2014
docker@boot2docker:~$

If you don’t see something similar to that, run /Applications/boot2docker.app and try again.

Otherwise, type exit to exit the virtual machine.

With a working boot2docker installation, we’re going to first create the non-Guest-Additions profile that we’re using right now. To do that, we’ll be using boot2docker config to dump the current profile data into a file that we’ll use to tell boot2docker which profile we want.

First, change into the .boot2docker directory.

> cd ~/.boot2docker

Next, dump the config data into a file we’ll call profile. Because boot2docker automatically uses ~/.boot2docker/profile as the default profile (if it’s available), we can be sure the command boot2docker always references that profile.

> boot2docker config > profile

Let’s make a guest-additions profile based on the default profile.

> cp profile profile-guest-additions

Now, we’ll make two changes to the profile so it will use the Guest-Additions ISO and virtual machine. Edit profile-guest-additions and make the following changes:

VM = "boot2docker-vm-guest-additions"
ISO = "/Users/[USER]/.boot2docker/boot2docker-guest-additions.iso"

Now that we have two separate profiles, we need the actual Guest Additions ISO. Let’s grab that:

> curl -LO http://static.dockerfiles.io/boot2docker-v1.2.0-virtualbox-guest-additions-v4.3.14.iso

Rename the ISO to the filename we specified in profile-guest-additions.

> mv boot2docker-v1.2.0-virtualbox-guest-additions-v4.3.14.iso boot2docker-guest-additions.iso

Let’s test things out. First, bring the normal boot2docker virtual machine down:

> boot2docker down

Initialize the virtual machine for Guest Additions and then bring up by specifying the environment variable: BOOT2DOCKER_PROFILE

> BOOT2DOCKER_PROFILE=~/.boot2docker/profile-guest-additions boot2docker init
> BOOT2DOCKER_PROFILE=~/.boot2docker/profile-guest-additions boot2docker up

If all went well, SSHing into the virtual machine should give us an extra line mentioning Guest Additions:

> BOOT2DOCKER_PROFILE=~/.boot2docker/profile-guest-additions boot2docker ssh
                        ##        .
                  ## ## ##       ==
               ## ## ## ##      ===
           /""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
           \______ o          __/
             \    \        __/
              \____\______/
 _                 _   ____     _            _
| |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|

  boot2docker with VirtualBox guest additions version 4.3.14

boot2docker: 1.2.0
             master : e75396e - Fri Aug 22 06:03:48 UTC 2014

Switching back to the original virtual machine is as simple as bringing down the Guest Additions version, and bringing up the original by excluding BOOT2DOCKER_PROFILE:

> BOOT2DOCKER_PROFILE=~/.boot2docker/profile-guest-additions boot2docker down
> boot2docker up

While you can export the BOOT2DOCKER_PROFILE environment variable, doing so also makes it easy to forget which virtual machine is being used.

Sign up for Turret.IO — the only data-driven marketing platform made specifically for developers.

Leave a Reply

Your email address will not be published. Required fields are marked *