Saturday, August 22, 2015

Getting Started with Vagrant

Vagrant is a virtualization technology that allows you to configure virtualization software such as Linux Containers and VirtualBox. It is commonly used together with orchestration tools like Ansible, and Chef.

To get started, download Vagrant here - https://www.vagrantup.com/downloads.html

Create a folder and run

vagrant init

This should create a VagrantFile.

Similar to Docker, Vagrant is dependent on base images. Let's begin by downloading an ubuntu box:

vagrant box add hashicorp/precise32

Open VagrantFile and edit the following:

config.vm.box = "hashicorp/precise32"

You can always find other boxes here:

https://atlas.hashicorp.com/boxes/search

Let's boot up the box:

vagrant up
vagrant ssh

You can check the status of the machine by running:

vagrant status

Do not delete the folder /vagrant, it's a synced folder

Let's begin by loading a script that will install apache.

In your hosts machine's root folder, create s file called bootstrap.sh

vi bootstrap.sh

Add the following:

apt-get update
apt-get install -y apache2
if ! [ -L /var/www ]; then
  rm -rf /var/www
  ln -fs /vagrant /var/www
fi

In VagrantFile, add

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise32"
  config.vm.provision :shell, path: "bootstrap.sh"
end

Reload the provision:

vagrant reload --provision

Test the status of apache:

vagrant ssh
service apache2 status

Try running:

wget -qO- 127.0.0.1

Add the following line in VagrantFile for port forwarding, so we can see webpages from our host browsers

config.vm.network :forwarded_port, guest: 80, host: 4567

Run

vagrant reload

In your browser, do

http://127.0.0.1:4567

If you want to share this image to Altas to share/backup your files, register an account at

https://atlas.hashicorp.com/

Run

vagrant login
vagrant share

In the browser, access the url that's outputted by the terminal.

When you finished sharing, Ctrl = C to terminate it.

When you are done with your vagrant box, you can use the following:

vagrant suspend - state is saved, quick to start up, consumes space
vagrant halt - guest OS is shut down, consumes space
vagrant destroy - removes the guest machine

You can use vagrant up to start it again.

By default, the vagrant box is backed with Virtual Box.

But you can easily change it to VMware or AWS by:

vagrant up --provider-vmware_fusion
vagrant up --provider=aws




27 comments:

  1. Thanks to amazing post. And great articles of contents and vagrant information's.

    hadoop training

    ReplyDelete
  2. Great post!I am actually getting ready to across this information,i am very happy to this commands.Also great blog here with all of the valuable information you have.Well done,its a great knowledge.

    ccna training in chennai adyar

    ReplyDelete
  3. Thanks for this blog. All screenshots can explain the full blogs easily. This is very easy to understand. Using this screen shots know the details becomes easy.
    PPC Services Chennai

    ReplyDelete
  4. Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..
    Digital Marketing Company in Chennai

    ReplyDelete
  5. Thanks Admin for sharing such a useful post, I hope it’s useful to many individuals for developing their skill to get good career.
    online Python training
    python training in chennai

    ReplyDelete
  6. Thank you for an additional great post. Exactly where else could anybody get that kind of facts in this kind of a ideal way of writing? I have a presentation next week, and I’m around the appear for this kind of data.
    Data science course in bangalore | Data Science training with placement in Bangalore

    ReplyDelete
  7. Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
    Java training in Bangalore|best Java training in Bangalore
    Java training in Chennai
    Java training in Bangalore
    Java online training
    Java training in Pune

    ReplyDelete
  8. Nice tutorial. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated tutorials…
    Devops Training in Chennai | Devops Training Institute in Chennai

    ReplyDelete
  9. Thanks For Sharing The information The Information Shared Is Very Valuable Please Keep Updating us The Information shared Is Very Valuable Python Online Course Data Science Online Course Aws Online Course

    ReplyDelete
  10. BA Revaluation Result 2019
    Hey Nice Blog!! Thanks For Sharing!!! Wonderful blog & good post. It is really very helpful to me, waiting for a more new post. Keep Blogging

    ReplyDelete
  11. Truly mind blowing blog went amazed with the subject they have developed the content. These kind of posts really helpful to gain the knowledge of unknown things which surely triggers to motivate and learn the new innovative contents. Hope you deliver the similar successive contents forthcoming as well.

    Data Science certification in Raipur

    ReplyDelete