The Vagrant basic command USES detail
- 2020-05-13 04:20:40
- OfStack
The basic command of Vagrant is explained in detail as follows:
1. Check the current version
# vagrant --version
Vagrant 1.8.1
2. List all box
# vagrant box list
centos/7 (virtualbox, 1603.01)
ubuntu/trusty64 (virtualbox, 20160406.0.0)
3. Add one box
# vagrant box add ADDRESS
1) box abbreviation
Vagrant can https from here: / / atlas hashicorp. com/boxes/various Vagrant search download image file.
# vagrant box add ubuntu/trusty64
2) add remote box via the specified URL
# vagrant box add https://atlas.hashicorp.com/ubuntu/boxes/trusty64
3) add 1 local box
# vagrant box add CentOS7.1 file:///D:/Work/VagrantBoxes/CentOS-7.1.1503-x86_64-netboot.box
4. Initialize a new VM
# vagrant init ubuntu/trustry64
This command creates a configuration file named Vagrantfile in the current directory, which looks like this:
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
end
When Vagrant is started in this directory, Vagrant will download the box "ubuntu/trusty64" from the Internet to the local location and use it as the image of VM.
To search for available box, look here: https: / / atlas hashicorp. com/boxes
5. Start VM
# vagrant up
If we want to start any VM, first go to the directory with the Vagrantfile configuration file, and then execute the command above. The console output is usually as follows:
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'ubuntu/trusty64-juju' could not be found. Attempting to find a
nd install...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Loading metadata for box 'ubuntu/trusty64-juju'
default: URL: https://atlas.hashicorp.com/ubuntu/trusty64-juju
==> default: Adding box 'ubuntu/trusty64-juju' (v20160707.0.1) for provider: vir
tualbox
default: Downloading: https://atlas.hashicorp.com/ubuntu/boxes/trusty64-juju
/versions/20160707.0.1/providers/virtualbox.box
==> default: Waiting for cleanup before exiting...
default: Progress: 0% (Rate: 0/s, Estimated time remaining: --:--:--):--)
6. Log on to VM with SSH enabled
Enter the directory where the Vagrantfile configuration file is located and execute the following command:
# vagrant box list
centos/7 (virtualbox, 1603.01)
ubuntu/trusty64 (virtualbox, 20160406.0.0)
0
Note that the SSH client must be installed on the machine.
7. Turn off VM
Enter the directory where the Vagrantfile configuration file resides and execute the following command:
# vagrant box list
centos/7 (virtualbox, 1603.01)
ubuntu/trusty64 (virtualbox, 20160406.0.0)
1
8. Destroy VM
# vagrant box list
centos/7 (virtualbox, 1603.01)
ubuntu/trusty64 (virtualbox, 20160406.0.0)
2
Such as:
vagrant destroy ubuntu/trusty64
This command will stop VM and destroy all created resources.