Vagrant or Dockers?

Vagrant vs. Docker

Vagrant vs Docker: Which is better for WordPress development?

After reading the above article I’ve decided to start with Vagrant, and maybe some other time I’ll use Docker.

Vagrant

Vagrant – the command line utility for managing the lifecycle of virtual machines.

Setup

First install VirtualBox (other virtualization-software also possible):

Then install Vagrant:

GETTING STARTED

Project setup

mkdir vagrant_getting_started
cd vagrant_getting_started
vagrant init

Change VAGRANT_HOME directory on windows

Read this:

Change VAGRANT_HOME directory on windows

Open a Command Prompt (Admin) and type this command:

setx VAGRANT_HOME "X:/your/path" /M

That’s it.

Installing a box

Boxes are added to Vagrant with vagrant box add. This stores the box under a specific name so that multiple Vagrant environments can re-use it.

vagrant box add hashicorp/precise64

Or, download a different box, see: https://atlas.hashicorp.com/boxes/search.

Using a box

Now that the box has been added to Vagrant, we need to configure our project to use it as a base. Open the Vagrantfile and change the contents to the following:

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise64"
end

The “hashicorp/precise64” in this case must match the name you used to add the box above. This is how Vagrant knows what box to use. If the box was not added before, Vagrant will automatically download and add the box when it is run.

Up and SSH

It is time to boot your first Vagrant environment. Run the following from your terminal:

vagrant up

You will not actually see anything though, since Vagrant runs the virtual machine without a UI. To prove that it is running, you can SSH into the machine:

vagrant ssh

This command will drop you into a full-fledged SSH session.

When you are done fiddling around with the machine, run

vagrant destroy

back on your host machine, and Vagrant will terminate the use of any resources by the virtual machine.

The vagrant destroy command does not actually remove the downloaded box file. To completely remove the box file, you can use the

vagrant box remove NAME

command.

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *