How to use Vagrant Docker provisioner with PowerKVM

Vagrant provisioners allow software installation, configuration changes and other changes to the machines. Vagrant provides multiple provisioners, starting from simple shell scripts to complete configuration management systems, like chef, puppet, ansible etc.

Provisioners get executed at specific points during the lifetime of a Vagrant machine.

From Vagrant docs,

  • On the first vagrant up that creates the environment, provisioning is run. If the environment was already created and the up is just resuming a machine or booting it up, they won’t run unless the –provision flag is explicitly provided.
  • When vagrant provision is used on a running environment.
  • When vagrant reload –provision is called. The –provision flag must be present to force provisioning.

In this article, we’ll see how to use the Vagrant docker provisioner with PowerKVM.

My setup looks like the following

In order to create Vagrant machines on PowerKVM you need to use the vagrant-libvirt plugin. For more details on using vagrant-libvirt plugin with PowerKVM refer to my previous article.

Using the docker provisioner with PowerKVM is pretty straight forward.

Here is a sample Vagrantfile for creating docker containers on PowerKVM VM created by vagrant-libvirt.

[pradipta@voldemort vagrant-box]$ cat Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

# 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|
  # All Vagrant configuration is done here. The most common configuration
  # options are documented and commented below. For a complete reference,
  # please see the online documentation at vagrantup.com.
  config.vm.provider :libvirt do |libvirt|
       libvirt.host = "my.powerkvm.host"
       libvirt.connect_via_ssh = "true"
       libvirt.uri = "qemu+ssh://root@my.powerkvm.host/system"
       libvirt.management_network_name = "default"
       libvirt.management_network_address = "192.168.122.0/24"
  end

  config.vm.define :test_vagrant do |test1|
    test1.vm.box = "trustyppc64"
    test1.vm.box_url = "http://my.fileserver.com/trustyppc64.box"
    test1.vm.provider :libvirt do |domain|
      domain.memory = 2048
      domain.cpus = 1
      domain.video_type = "vga"
    end
  end
 
 #Install docker for Ubuntu ppc64 from custom location 
  config.vm.provision "shell", path: "install_docker.sh"

 #Download a docker image and run it via the docker provisioner
  config.vm.provision "docker" do |d|
     d.pull_images "my.private.docker.registry/pradipta/ubuntu_ppc64le"
     d.run "ubuntu_ppc64le",
         image: "my.private.docker.registry/pradipta/ubuntu_ppc64le”,
         cmd: "cat /etc/lsb-release"
  end

   #Check the container logs
  config.vm.provision "shell" do |s|
    s.inline = "sudo docker logs ubuntu_ppc64le"
  end
end

install_docker.sh is a simple shell script to download docker for Ubuntu ppc64 from Unicamp repository. This is required currently till docker becomes part of official distro repository for Power. For more details on docker on Ubuntu for Power servers check my previous article on the same topic.

[pradipta@voldemort vagrant-box]$ cat install_docker.sh
#!/bin/bash
RET=`dpkg -s docker.io-1.3.0-dev 2>/dev/null`
if [ $? != 0 ]
then
    #Download docker binary for Ubuntu on Power from Unicamp site
    wget ftp://ftp.unicamp.br/pub/linuxpatch/docker-ppc64/ubuntu/14_10/docker.io-1.3.0-dev_ppc64el.deb
    sudo dpkg -i docker.io-1.3.0-dev_ppc64el.deb
fi

In my case the vagrant machine is already running. Hence explicitly starting the provisioning by calling ‘vagrant provision’

[pradipta@voldemort libvirt]$ vagrant provision
[snip]
==> test1: Running provisioner: shell...
    test1: Running: /tmp/vagrant-shell20141216-22769-rld8r3.sh
==> test1: Running provisioner: docker...
    test1: Configuring Docker to autostart containers...
==> test1: Pulling Docker images...
[snip]
==> test1: Starting Docker containers...
==> test1: -- Container: ubuntu_ppc64le
==> test1: Running provisioner: shell...
    test1: Running: inline script
==> test1: stdin: is not a tty
==> test1: DISTRIB_ID=Ubuntu
==> test1: DISTRIB_RELEASE=14.04
==> test1: DISTRIB_CODENAME=trusty
==> test1: DISTRIB_DESCRIPTION="Ubuntu 14.04 LTS"

As you can see using Vagrant Docker provisioner with PowerKVM is pretty straight-forward.

Pradipta Kumar Banerjee

I'm a Cloud and Linux/ OpenSource enthusiast, with 16 years of industry experience at IBM. You can find more details about me here - Linkedin

You may also like...