So I am a beginner when it comes to vagrant. While going through the online content and documentation related to it, I came across 3 vagrant commands namely, 'destroy', 'remove' and 'halt'. Can someone clarity what exactly would they do ?
I know that : DESTROY: This command stops the running machine Vagrant is managing and destroys all resources that were created during the machine creation process. After running this command, your computer should be left at a clean state, as if you never created the guest machine in the first place.
HALT: This command shuts down the running machine Vagrant is managing.
REMOVE: This command removes a box from Vagrant that matches the given name. So does this remove the box from hard drive ?
I am not able to imagine the difference in these commands. what i feel is that halt is just like shutdown the VM. The resources are still allotted to it. destroy is like the state where there was no VM present.
remove means, even removing the box. So you'll have to download it again. Is that correct ?
Command: vagrant destroy [name|id] This command stops the running machine Vagrant is managing and destroys all resources that were created during the machine creation process. After running this command, your computer should be left at a clean state, as if you never created the guest machine in the first place.
Command: vagrant suspend [name|id] A suspend effectively saves the exact point-in-time state of the machine, so that when you resume it later, it begins running immediately from that point, rather than doing a full boot.
Command: vagrant resume [name|id] This resumes a Vagrant managed machine that was previously suspended, perhaps with the suspend command. The configured provisioners will not run again, by default. You can force the provisioners to re-run by specifying the --provision flag.
(Kevin answered correctly, +1! I just provide a bit more information for vagrant beginner)
First you need to understand how vagrant works.
When you create a vagrant environment you will create a vagrant file (you can use the command vagrant init bento/ubuntu-16.04
) - the Vagrantfile
will look like (reduced to minimal)
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-16.04"
end
when you will spin up vagrant (vagrant up
) to run a VM, what it will do is :
bento/ubuntu-16.04
(this is already a VM in fact which will be the base image of further VM)
once the box is downloaded, it remains in your $HOME/.vagrant.d/boxes
folder and can be used for any other VagrantfileYou can download any number of box and store them in your .vagrant.d
folder and you can see the list of available box running
$ vagrant box list
You can see the VM that vagrant currently managed by running
$ vagrant global-status
Now to answer your question, the command will have impact on different level:
vagrant halt
You understand correctly - you can review my previous answer for further reading on In Vagrant which is better out of halt and suspend?
vagrant destroy
This command destroys all VM resources (but not any vagrant resources) so all the VirtualBox VM files are destroyed but the box remained untouched.
You can check by running vagrant box list
after you run vagrant destroy
on a VM, all boxes remain untouched.
vagrant remove
This command remove (destroy) the vagrant resources so if you want to create a new VM later against the base box, vagrant would need to re-download from internet.
Note that after you have created the VM, you can remove the box and vagrant will still work correctly so vagrant remove
has no effect on the VirtualBox resources and all VMs remain untouched
Note on box usage:
you can have multiple versions of the same box
$ vagrant box list
bento/ubuntu-16.04 (vmware_desktop, 2.3.0)
bento/ubuntu-16.04 (vmware_desktop, 2.3.7)
you can have same version of box for different providers
$ vagrant box list
bento/ubuntu-16.04 (virtualbox, 201708.22.0)
bento/ubuntu-16.04 (vmware_desktop, 2.3.0)
bento/ubuntu-16.04 (vmware_desktop, 2.3.7)
Welcome to SO! This is a great question. To clarify vagrant box remove YOUR_BOX_NAME
is for removing a box completely such as hashicorp/precise64
where indeed you have to re-download it to use it. Now vagrant destroy
simply destroys the Virtual Machine so it will not show up in your manager, for example if you use Oracle VM Manager. I hope this provides clarification.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With