服务器之家:专注于服务器技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|Windows11|

服务器之家 - 服务器系统 - Linux - Vagrant基本命令使用详解

Vagrant基本命令使用详解

2021-11-30 15:56资深架构师 Linux

本篇文章主要介绍了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的运行,并销毁所有创建的资源。

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

原文链接:http://blog.csdn.net/chszs/article/details/51925179

延伸 · 阅读

精彩推荐