Vagrant基本命令使用详解

Vagrant基本命令详解,具体如下:

1、检查当前的版本

# vagrant --version
Vagrant 1.8.1

2、列出所有的box

# vagrant box list
centos/7    (virtualbox, 1603.01)
ubuntu/trusty64 (virtualbox, 20160406.0.0)

3、添加一个box

# vagrant box add ADDRESS

1)box名简写

Vagrant可以从这里https://atlas.hashicorp.com/boxes/search 下载各种Vagrant映像文件。

# vagrant box add ubuntu/trusty64

2)通过指定的URL添加远程box

# vagrant box add https://atlas.hashicorp.com/ubuntu/boxes/trusty64

3)添加一个本地box

# vagrant box add CentOS7.1 file:///D:/Work/VagrantBoxes/CentOS-7.1.1503-x86_64-netboot.box

4、初始化一个新VM

# vagrant init ubuntu/trustry64

此命令会在当前目录创建一个名为Vagrantfile的配置文件,内容大致如下:

Vagrant.configure(2) do |config|
 config.vm.box = "ubuntu/trusty64"
end

当在此目录启动Vagrant后,Vagrant会从互联网下载“ubuntu/trusty64”这个box到本地,并使用它作为VM的映像。

要搜索可用的box,查看这里: https://atlas.hashicorp.com/boxes

5、启动VM

# vagrant up

如果我们想启动任意VM,首先进入有Vagrantfile配置文件的目录,然后执行上面的命令。控制台的输出通常如下:

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、启用SSH登陆VM

进入Vagrantfile配置文件所在的目录,执行以下命令:

# vagrant ssh

要注意,本机上必须先安装SSH客户端。

7、关闭VM

进入Vagrantfile配置文件所在的目录,执行以下命令:

# vagrant halt

8、销毁VM

# vagrant destory [name|id]

比如:

vagrant destroy ubuntu/trusty64

此命令会停止VM的运行,并销毁所有创建的资源。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持呐喊教程。

声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:notice#nhooo.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。