What is the difference between vagrant remove, halt and destroy

前端 未结 2 1678
长发绾君心
长发绾君心 2020-12-31 20:12

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\', \'

相关标签:
2条回答
  • 2020-12-31 20:37

    (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 :

    1. download from internet the box 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 Vagrantfile
    2. vagrant will clone the box and create a VM in VirtualBox. You can open Virtualbox and see the VM in the list of available VM. The VM files will be stored in VirtualBox folder.

    You 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)
      
    0 讨论(0)
  • 2020-12-31 20:58

    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.

    0 讨论(0)
提交回复
热议问题