我是靠谱客的博主 清秀小甜瓜,这篇文章主要介绍Vagrant基本命令使用详解,现在分享给大家,希望可以做个参考。

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

1、检查当前的版本

复制代码
1
2
# vagrant --version Vagrant 1.8.1

2、列出所有的box

复制代码
1
2
3
# vagrant box list centos/7 (virtualbox, 1603.01) ubuntu/trusty64 (virtualbox, 20160406.0.0)

3、添加一个box

复制代码
1
# vagrant box add ADDRESS

1)box名简写

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

复制代码
1
# vagrant box add ubuntu/trusty64

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

复制代码
1
# vagrant box add https://atlas.hashicorp.com/ubuntu/boxes/trusty64

3)添加一个本地box

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

4、初始化一个新VM

复制代码
1
# vagrant init ubuntu/trustry64

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

复制代码
1
2
3
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

复制代码
1
# vagrant up

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

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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配置文件所在的目录,执行以下命令:

复制代码
1
# vagrant ssh

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

7、关闭VM

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

复制代码
1
# vagrant halt

8、销毁VM

复制代码
1
# vagrant destory [name|id]

比如:

复制代码
1
vagrant destroy ubuntu/trusty64

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

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

最后

以上就是清秀小甜瓜最近收集整理的关于Vagrant基本命令使用详解的全部内容,更多相关Vagrant基本命令使用详解内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(132)

评论列表共有 0 条评论

立即
投稿
返回
顶部