Saturday, November 17, 2018

Start using Vagrant, now! - Part 2

So here we saw how to setup vagrant on your machine.
And now we will cover how to setup Ubuntu 18.04 as Vagrant box.


Getting it up is relatively easy, if you have basic knowledge of Linux.
Before we start with above, we will need one Linux console emulator. There are quite a few to choose from. But personally I use git command line tool. Other options are cmderconemu

Once you are ready with command line tool, create one folder to start with your vagrant boxes.
Generally what I follow is create one directory "vagrant boxes" in drive where I have most free space.
And under that folder, I create folder per box. e.g. lamp, es, etc.

Considering now you have everything in place. 
Let's start with installing Ubuntu 18.04.

Under your chosen folder, create a file `Vagrantfile`, and paste below config (same was provided in my last post)

Vagrant.configure("2") do |config|
  config.vm.define :lamp do |lamp|
    lamp.vm.box = "ubuntu/bionic64"
    lamp.vm.network "forwarded_port", guest: 3306, host: 8306, protocol: "tcp"
lamp.vm.network "forwarded_port", guest: 80, host: 8380, protocol: "tcp"
    lamp.vm.hostname = "lamp"
lamp.vm.synced_folder "local/", "/home/jthakar/local"
  end
end

Once done, open command line tool. and run below command.

vagrant up

This will first check your config, then check for ubuntu/bionic64 (which is vagrant box for ubuntu 18.04) and download same if not present in your system already. 
once downloaded successfully, this will fire up instance.

once its up, you can use below command to ssh in the box.

vagrant ssh

and yes, this is it you have box/vm ready in 2 minutes.

now you can run below command to stop it.

vagrant halt

check out cheat sheet for Vagrant commands here.




No comments:

Post a Comment

Installing ruby on rails with Apache on Ubuntu 16.04 LTS for production

Recently I decided to start with ROR and move away from PHP. So I decided to first setup production like environment for rails. And to my...