Fun with Vagrant and Docker containers

This article requires some knowledge about Vagrant and Docker.

Almost any reasonable deploy process now requires a docker box. Docker is awesome but I’d rather have an isolated environment for my containers.

Here is where vagrant’s docker priovider comes in to play. Vagrant guys did a great job explaining abstraction here.

As always things are not so easy when you actually try to implement Vagrant Docker Proxy/Host on your own.

After a day of googling errors caused by

1
vagrant up
I figured that Vagrant is too green for automating Docker installation. Another issue came up after I failed to install Docker on linux box. Even if you get Docker instaled you instantly get a permission error.

All issues above fixed with custom

1
shell.sh
provision script:

#!/bin/bash
sudo apt-get update &&
sudo apt-get install curl -y &&
curl -sSL https://get.docker.com/ubuntu/ | sudo sh &&
sudo usermod -a -G docker vagrant &&
ps aux | grep 'sshd:' | awk '{print $2}' | xargs kill

1
curl -sSL https://get.docker.com/ubuntu/ | sudo sh &&
will take care of installing correct binaries.

Here’s working

1
Vagrantfile
for host machine:

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|

  config.vm.provision "shell", path: "shell.sh"
  config.vm.box = "ubuntu/trusty64"
 
  config.vm.provider :virtualbox do |vb|
      vb.name = "dockerhost"
  end
end

Then you can reference other containers in main

1
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|
  config.vm.provider "docker" do |v|
    v.vagrant_vagrantfile = "./docker-host/Vagrantfile"
  end

  config.vm.define "core" do |v|
    v.vm.provider "docker" do |d|
      d.build_dir = "."
    end
  end

  config.vm.define "db" do |v|
    v.vm.provider "docker" do |d|
      d.image = "paintedfox/postgresql"
      d.name = "db"
    end 
  end
end

That’s it!

Phoenix On A Raspberry Pi with Exrm

## Intro> Before you read this be sure to look at:>> 1. [Phoenix Advanced Deployment](http://www.phoenixframework.org/docs/advanced-deplo...… Continue reading