Phusion white papers Phusion overview

Docker-friendly Vagrant boxes

By Hongli Lai on November 8th, 2013

Vagrant

We heavily utilize Vagrant in our development workflow. Vagrant is a tool for easily setting up virtual machines as development environments, making it easy to distribute development environments and making them reconstructible and resetable. It has proven to be an indispensable tool when working in development teams with more than 1 person, especially when not everybody uses the same operating system.

Lately we’ve been working with Docker, which is a cool new OS-level virtualization technology. Docker officially describes it as “iPhone apps for your server”, but being the hardcore system-level guys that we are, we dislike this description. Instead we’d like to describe Docker as “FreeBSD jails for Linux + an ecosystem to make it a joy to use”. Docker, while still young and not production-ready, is very promising and can make virtualization cheap and efficient.

Googling for Vagrant and Docker will yield plenty of information and tutorials.

Today, we are releasing Docker-friendly Vagrant boxes based on Ubuntu 12.04. Docker requires at least kernel 3.8, but all the Ubuntu 12.04 Vagrant boxes that we’ve encountered so far come with kernel 3.2 or 3.5, so that installing Docker on them requires a reboot. This makes provisioning a VM to be significantly more painful than it should be.

Update April 23 2014: we now also provide Vagrant boxes based on Ubuntu 14.04. The 12.04 boxes are still available. See the website for more information.

These boxes differ from the ones provided by vagrantup.com in the following ways as well:

  • We provide 2 virtual CPUs by default, so that the boxes can make better use of multicore hosts.
  • We provide more RAM by default: 1 GB.
  • We provide a bigger virtual hard disk: around 40 GB. So that you don’t have to worry about running out of disk space inside your VM.
  • We use LVM so that partitioning is easier.
  • The memory cgroup and swap accounting are turned on, for some Docker features.
  • Chef is installed via the Ubuntu packages that they provide, instead of via RubyGems. This way the box doesn’t have to come with Ruby by default, making the environment cleaner.
  • Our VMWare Fusion boxes recompile VMWare Tools on every kernel upgrade, so that Shared Folders keep working even if you change the kernel.

These base boxes are automatically built from Veewee definitions. These definitions makes building boxes quick and unambigious. The entire building process is described in the definitions; no manual intervention is required.

We provide prebuilt boxes at https://oss-binaries.phusionpassenger.com/vagrant/boxes/, but you can build them yourself if you so wish.

The boxes are also available on Vagrant Cloud.

Related resources: Github | Prebuilt boxes | Vagrant Cloud | Discussion forum | Twitter

Using these boxes in Vagrant

If you have Vagrant 1.5, you can use our boxes through Vagrant Cloud:

vagrant init phusion/ubuntu-14.04-amd64
# -OR-
vagrant init phusion/ubuntu-12.04-amd64

On older Vagrant versions, you can modify your Vagrantfile to use our boxes. Here is an example Vagrantfile which works with both VirtualBox and VMWare Fusion. It also automatically installs the latest version of Docker.

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "phusion-open-ubuntu-14.04-amd64"
  config.vm.box_url = "https://oss-binaries.phusionpassenger.com/vagrant/boxes/latest/ubuntu-14.04-amd64-vbox.box"
  # Or, for Ubuntu 12.04:
  #config.vm.box = "phusion-open-ubuntu-12.04-amd64"
  #config.vm.box_url = "https://oss-binaries.phusionpassenger.com/vagrant/boxes/latest/ubuntu-12.04-amd64-vbox.box"

  config.vm.provider :vmware_fusion do |f, override|
    override.vm.box_url = "https://oss-binaries.phusionpassenger.com/vagrant/boxes/latest/ubuntu-14.04-amd64-vmwarefusion.box"
    #override.vm.box_url = "https://oss-binaries.phusionpassenger.com/vagrant/boxes/latest/ubuntu-12.04-amd64-vmwarefusion.box"
  end

  if Dir.glob("#{File.dirname(__FILE__)}/.vagrant/machines/default/*/id").empty?
    # Install Docker
    pkg_cmd = "wget -q -O - https://get.docker.io/gpg | apt-key add -;" \
      "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list;" \
      "apt-get update -qq; apt-get install -q -y --force-yes lxc-docker; "
    # Add vagrant user to the docker group
    pkg_cmd << "usermod -a -G docker vagrant; "
    config.vm.provision :shell, :inline => pkg_cmd
  end
end

You can login with username vagrant and password vagrant. This user has sudo privileges. The root user also has password vagrant.

The prebuilt boxes are available at https://oss-binaries.phusionpassenger.com/vagrant/boxes/.

Final words

Enjoy these Vagrant boxes!

You may also want to check our other products, such as Phusion Passenger, which is an application server which makes Ruby, Python, Node.js and Meteor deployment extremely simple. Or simply follow us on Twitter.

  • Paul Bowsher

    ‘Docker officially describes it as “iPhone apps for your server”’

    Never seen that anywhere, and Google only turns up this blog post. Source please, as that’s a really stupid claim to make if they didn’t say it. It makes Docker look bad.

  • http://www.phusion.nl/ Hongli Lai

    http://blog.docker.io/2013/08/websockets-dockerfile-upgrade-better-registry-support-expert-mode-and-more/
    I quote:

    think “iPhone apps for the server”

    Before their recent website revamp, they even had it on the about page.

  • Paul Bowsher

    I stand corrected.

  • ubermuda

    Is swap accounting enabled on these boxes?

  • http://www.phusion.nl/ Hongli Lai

    These are standard Ubuntu 12.03 boxes with almost nothing installed, though with kernel 3.8. I don’t think swap accounting is enabled by default.

    Note that these boxes don’t include Docker. You’ll have to install the Ubuntu packages using APT and your favorite provisioner. The point of these boxes is to avoid having to reboot the VM as part of the Vagrant provisioning process, which is quite an awkward process.

    Although if people *want* it, we can add the Docker repo by default. Just let us know.

  • ubermuda

    That is precisely why I ask :-) I ran into the issue today on my own vagrant box, trying to limit memory for a container and running into the following message:

    WARNING: Your kernel does not support memory swap capabilities. Limitation discarded.

    Swap accounting must be enabled at kernel boot time through a parameter (passed by grub in our case).

    Long story short, anyone wanting to limit memory for a container using your boxes will actually have to reboot the VM as part of the provisioning process.

    This might not be mister Everyone’s use-case, but heh, it doesn’t cost much to be prepared and make those boxes docker-friendlier than they already are ;)

    More infos: http://docs.docker.io/en/latest/installation/kernel/#memory-and-swap-accounting-on-debian-ubuntu

  • http://www.phusion.nl/ Hongli Lai

    Interesting, I didn’t know about this boot-time option. I’ll look into enabling this by default.

  • http://www.phusion.nl/ Hongli Lai

    We’ve now rebuilt and uploaded the VirtualBox box with swap accounting enabled. VMWare Fusion box is being uploaded.

  • ubermuda

    Awesome! You rock.

  • http://boinkor.net Andreas Fuchs

    These are super useful, thanks for posting them!

    Sadly, I’ve found a problem in the VMware base box: If you bring it up initially, everything works, but the second time you bring it up (after a `vagrant halt ; vagrant up`), it hangs trying for the HGFS kernel module to load.

    I could reproduce this in a packer box that I’m building myself, and I think I have tracked the root cause of this down to the kernel upgrade going through and the vmware tools being installed only for the old kernel. The solution for me was to install the kernel 3.8.x, reboot, and only after the reboot to install vmware tools.

  • http://www.phusion.nl/ Hongli Lai

    We actually already take care of this. We patched the VMWare Tools and integrated them into DKMS, so that on every kernel upgrade the tools are automatically recompiled.

    But maybe you provisioning script upgraded the kernel to a version that the VMWare Tools couldn’t automatically recompile against. Try modifying your provisioning scripts so that they don’t upgrade the kernel.

  • http://boinkor.net Andreas Fuchs

    Hum, not really. All this vagrantfile does is to use the “docker” provisioner to bring a container up. Maybe vagrant’s automatic installation of docker on Ubuntu installs a new kernel also?

  • http://www.phusion.nl/ Hongli Lai

    Could you check whether your kernel is being upgraded? It has worked for us so far.

  • Florian Heigl

    Thanks for your description of Docker. After all just a LXC wrapper + tarballs like Vagrant is a VirtualBox wrapper plus images?

    I’ll just need to figure out the hype. Is it just so amazing if you don’t have the same background (chroots, jails, zones, xen PV, NFS netbooting default) and it comes nicely packaged? Or what the f*** am I missing why this is so amazing?

  • Barry A.

    Note on memory and cgroup accounting: the Docker KB details were deleted but a PR was opened to restore them. https://github.com/dotcloud/docker/pull/4251

  • Barry A.

    Correct, it’s not enabled by default. There will be a couple of “WARNING:” running `docker info` if it’s not enabled. Fix: https://github.com/dotcloud/docker/issues/4250#issuecomment-35566530

  • Justizin

    it kind of makes sense, because iOS / OSX apps are sandboxed, but Docker is nowhere near as fun as Bundles.