Using Vagrant to create a PostgreSQL DB server

Vagrant looking for workI started using Vagrant a few months ago, and its been a real pleasure to use and has made my web development work so much more easier.

If you don't know what Vagrant is , then check it out at https://www.vagrantup.com/.

Basically it allows you to create one or more virtual machines (VMs) on your own desktop or laptop.

So, for example, I use a Apple MacBook  and I use Vagrant to run Ubuntu 14 & Ubuntu 16 (at time of writing) VMs to do my development on.

This is the vagrant file I use to create the PostgreSQL server I use for development.

# -*- mode: ruby -*-
# vi: set ft=ruby :

setup = {
  "name": "MYVM_BOX",
  "ip_address": "192.168.1.59",
  "memory": 512
}
Vagrant.configure("2") do |config|
  config.vm.define setup[:name] do |vb|
    vb.vm.network :private_network, ip: setup[:ip_address]

    vb.vm.network "forwarded_port", guest: 22, host: 5922, id: "ssh"
    vb.vm.network "forwarded_port", guest: 5432, host: 5459

    vb.vm.box = "geerlingguy/ubuntu1604 "
    vb.vm.hostname = setup[:name]

    vb.vm.provider :virtualbox do |v|
    v.customize ["modifyvm", :id, "--memory", setup[:memory],"--nictype1", "virtio"]
    v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
    end

    vb.vm.synced_folder ".", "/home/vagrant/shared"
    vb.vm.provision "shell", path: 'provision.sh',run: "once"

  end
end

Leave a Reply

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