Vagrant, an open source product from HashiCorp, is something of a cross between a container orchestrator and a...
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
VM orchestrator. Vagrant makes it easier to deploy containers and VMs than Docker, and it takes less time to create a VM with Vagrant than Docker.
Vagrant enables the user to package his own development, test or production application and send that app to testers, users and developers, as well as migrate it through environments; the only requirements are that the target environment have Vagrant installed, a supported hypervisor and the BOX file that contains the Vagrant application.
Similar to how you would deploy containers with Docker, Vagrant allows you to package code, build completely installed systems and send them to or share them with others. Vagrant also provides automatic access to a shared file system, which requires an additional step in Docker.
Vagrant runs on most OSes, including Ubuntu, and uses the Oracle VirtualBox hypervisor. Vagrant also works with VMware, Hyper-V, Docker and Amazon Web Services, but be aware that VirtualBox doesn't always work on top of other hypervisors. If you try to install VirtualBox in a VM and receive the following error message, it means that the OS isn't able to access the virtualization capabilities of the Intel or Advanced Micro Devices chip: VBoxManage: error: VT-x is not available.
Vagrant can automatically download packaged containers you've created, or if you prefer, you can download packages created by other users from the Vagrant public repository.
To get started, install Vagrant and Oracle VirtualBox, and then enter the following command:
vagrant init hashicorp/precise64
This downloads hashicorp/precise64, a small Linux OS, and creates a file called VagrantFile in the directory where you run Vagrant. The VagrantFile is where you do additional configuration. Next, write a file called bootstrap.sh to send instructions to the Vagrant container to execute specific tasks, such as installing software or configuring network port forwarding.
The Vagrant file should look like this:
config.vm.box = "hashicorp/precise64"
config.vm.provision :shell, path: "bootstrap.sh"
After you've downloaded the image and created a bootstrap.sh, deploy containers with the vagrant up command.
Vagrant creates public keys for whoever's currently logged in, so there's no need for a password. To log into the Vagrant container, run the vagrant ssh command, and use CTRL-D to log out.
Use the vagrant destroy command to shut down and free any resources.
You can use a simple bootstrap.sh in Vagrant to install Nginx on the target container:
sudo apt-get update
sudo apt-get install nginx
You can't just copy HTML pages from your host computer to the target in bootstrap.sh -- instead, you have to use the following command:
config.vm.provision "file" ...
The vagrant box add command allows you to deploy containers and send them to other people so that they can use your environments and apps. You can also expose the container with the vagrant share command. This command creates a file, Secure Shell or URL from which a user can access the container. To create a URL, you have to install Ngrok; Ngrok.io is where your URL is hosted.
When you launch Vagrant, it shares your project directory with the /vagrant folder on the target system. Vagrant then automatically syncs any files you create or edit to and from your local host and the guest machine, which allows you to debug and edit using your local machine with familiar tools. The synced folders feature also allows you to pick other folders to share and sync.
Follow this DevOps lab Vagrant tutorial
Learn the difference between containers and VMs
Navigate container and VM integration