本地添加配置Vagrant box

vagrant init 时会从官网下载对应的Vagrant box,但是这个网速太晚了,我们可以使用迅雷下载后再配置。

 

一、迅雷下载box

1.获取下载地址,出现下载地址时,使用Ctrl + c 停止

https://vagrantcloud.com/ubuntu/boxes/xenial64/versions/20190720.0.0/providers/virtualbox.box为下载地址。

 

2.获取Vagrant官网box下载链接

下载链接公式:官网的版本详情链接 + /providers/virtualbox.box

https://app.vagrantup.com/boxes/search中找到需要的版本

例如:

 

点击进去后选定详细版本点击进去

 

复制最上方的URL地址,https://app.vagrantup.com/ubuntu/boxes/xenial64/versions/20190729.0.0

拼接后的下载地址:https://app.vagrantup.com/ubuntu/boxes/xenial64/versions/20190729.0.0/providers/virtualbox.box

 

使用迅雷下载后传输到Linux系统中

 

二、配置Vagrant box

1.新建配置文件 metadata.json 和下载的box放在同级目录


 

编辑metadata.json,添加以下内容:

{
    "name": "ubuntu/xenial64",#添加后的box名称
    "versions": 
    [
        {
            "version": "20190720.0.0",#版本号
            "providers": [
                {
                  "name": "virtualbox",
                  "url": "ubuntu_xenial64_20190720.box"#下载到本地的box路径
                }
            ]
        }
    ]
}

其中url也可以写相对路径指定其它的box文件。

 

添加:

vagrant box add metadata.json

查看:

vagrant box list

 

2.查看文档的添加格式

$ vagrant box add --help
Usage: vagrant box add [options] <name, url, or path>
 
Options:
 
    -c, --clean                      Clean any temporary download files
    -f, --force                      Overwrite an existing box if it exists
        --insecure                   Do not validate SSL certificates
        --cacert FILE                CA certificate for SSL download
        --capath DIR                 CA certificate directory for SSL download
        --cert FILE                  A client SSL cert, if needed
        --provider PROVIDER          Provider the box should satisfy
        --box-version VERSION        Constrain version of the added box
 
The box descriptor can be the name of a box on Vagrant Cloud,
or a URL, or a local .box file, or a local .json file containing
the catalog metadata.
 
The options below only apply if you're adding a box file directly,
and not using a Vagrant server or a box structured like 'user/box':
 
        --checksum CHECKSUM          Checksum for the box
        --checksum-type TYPE         Checksum type (md5, sha1, sha256)
        --name BOX                   Name of the box
    -h, --help                       Print this help

可以看到box add接受一个<name, url, or path>的参数,说明这个文件的路径可以是一个url或者是一个本地路径,而vagrant的box是可以被重命名的,比如同一个镜像文件文件,可以在在vagrant的box里叫不同的名字,这个名字在你的vagrantfile里是需要定义的,这样vagrant才能够通过box的名字找到具体的镜像文件。

所以最终添加本地命令的格式为:

vagrant box add --name box_name /path/of/box/file

 

 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值