手机版
你好,游客 登录 注册
背景:
阅读新闻

Vagrant基本命令详解

[日期:2016-10-26] 来源:Linux社区  作者:chszs [字体: ]

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的运行,并销毁所有创建的资源。

本文永久更新链接地址http://www.linuxidc.com/Linux/2016-10/136403.htm

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款