为了账号安全,请及时绑定邮箱和手机立即绑定

如何本地添加 vagrant box?

用DOS下载太慢了,听说可以复制链接直接下载,但是如何添加呢?

正在回答

5 回答

勤看文档啊,文档里啥都有:


通过vagrant --help我们知道了vagrant下面所有的命令:

$ vagrant --help
Usage: vagrant [options] <command> [<args>]

    -v, --version                    Print the version and exit.
    -h, --help                       Print this help.

Common commands:
     box             manages boxes: installation, removal, etc.
     connect         connect to a remotely shared Vagrant environment
     destroy         stops and deletes all traces of the vagrant machine
     global-status   outputs status Vagrant environments for this user
     halt            stops the vagrant machine
     help            shows the help for a subcommand
     hostmanager
     init            initializes a new Vagrant environment by creating a Vagrantfile
     login           log in to Vagrant Cloud
     package         packages a running vagrant environment into a box
     plugin          manages plugins: install, uninstall, update, etc.
     provision       provisions the vagrant machine
     rdp             connects to machine via RDP
     reload          restarts vagrant machine, loads new Vagrantfile configuration
     resume          resume a suspended vagrant machine
     share           share your Vagrant environment with anyone in the world
     ssh             connects to machine via SSH
     ssh-config      outputs OpenSSH valid configuration to connect to the machine
     status          outputs status of the vagrant machine
     suspend         suspends the machine
     up              starts and provisions the vagrant environment
     vbguest
     version         prints current and latest Vagrant version

For help on any individual command run `vagrant COMMAND -h`

Additional subcommands are available, but are either more advanced
or not commonly used. To see all subcommands, run the command
`vagrant list-commands`.

可以看到如果要管理box的话,有一个box命令,那么我们继续看box下有什么子参数:

$ vagrant box --help
Usage: vagrant box <subcommand> [<args>]

Available subcommands:
     add
     list
     outdated
     remove
     repackage
     update

For help on any individual subcommand run `vagrant box <subcommand> -h`

可以看到有add参数,显然就是用来添加box的,那我们继续看看box add怎么用:

$ 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


1 回复 有任何疑惑可以回复我~
#1

1w1 提问者

哦,知道了 原来 help可以这样用。 谢谢老师
2015-01-14 回复 有任何疑惑可以回复我~

https://zhuanlan.zhihu.com/p/25338468

0 回复 有任何疑惑可以回复我~

在windows上启动box的时候报了个警告:连接超时,然后就失败了(“Connect timeout retrying...”);这是那出了问题啊

0 回复 有任何疑惑可以回复我~

windows环境的话,先进入box所在的目录,然后

vagrant box add 自定义个名称 xxx.box

0 回复 有任何疑惑可以回复我~
#1

乐歌

例如:我下的box名称是centos-65-x64.box vagrant box add cent64 centos-65-x64.box
2015-03-12 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
洪大师带你解读Symfony 2框架
  • 参与学习       20582    人
  • 解答问题       245    个

洪大师教你玩转强大的框架-Symfony2,提高代码性能

进入课程

如何本地添加 vagrant box?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信