流浪汉的命令到底是做什么的?

令人惊讶的是,除了整个“入门”教程中的引用之外,没有关于 Vagrant 命令所做的任何文档。

到目前为止,我已经想明白了:

  • 管理“ 盒子
  • 关闭虚拟机然后删除其存储的图像?
  • gem
  • 关闭虚拟机
  • init-用一个新的 Vagrantfile 准备一个目录
  • 关闭虚拟机,然后把它转换成一个“包”,可以转换成一个盒子?(或者别的什么)
  • provision-只运行供应阶段(例如,Chef,Puppet...)
  • reload-修改 VM 配置(例如,重新应用 Vagrantfile) ,重新启动 VM,重新配置
  • 解除挂起(即解除冬眠)
  • ssh-打开到 VM 的 SSH shell 连接
  • ssh-config
  • status
  • suspend-使虚拟机休眠
  • 部分或全部: 复制一个 VM 映像来创建一个新的 VM,对它应用配置,启动它

这些对吗?其他人呢?我还是不太清楚 reloaddestroy/up之间的确切区别。

43076 次浏览

I agree with you that documentation at vagrantup is on the shorter side.

Some information can be gleaned from command help system.

  1. For example: gem command.

    Just type the command without arguments: vagrant gem -h and it produces the information that you may need.

    vagrant gem is used to install Vagrant plugins via the RubyGems system. In fact, vagrant gem is just a frontend to the actual gem interface, with the difference being that Vagrant sets up a custom directory where gems are installed so that they are isolated from your system gems.

  2. Vagrant ssh-config:

    Under the hood, when you execute vagrant ssh to ssh into VM. It is utilizing it's well known ssh key. The information on this key is provided by vagrant ssh-config. This is useful in case you want to change the well know key to your own private key and prepare boxes to use that.

    Also some times, you may want to use ssh based automation with your VMs. In that case, knowing which key is being used is useful. You could do use normal ssh command - ssh -i keyfile ..

  3. vagrant status <vmname>

    This command is a wrapper which provides the information on the status of vm. It could be running, saved and powered off.

  4. vagrant reload

    If you make any changes to the configuration in vagrantfile which needs to take effect. You may want to reload the VM. It re-runs the provisioning defined in the vagrantfile unless you ask it not too.

    It does not destroy the VM you have created from a base box. That means all the changes you have made to your VM, like say created a folder in your user directory will be there after reload.

    It is like reboot where it powers off your VM and then applies certain configuration change which can be applied only when VM has been powered off. and then power it on. Example: like attaching another SATA Virtual Disk.

  5. vagrant up

    This reads your configuration file - vagrantfile and then creates a VM from base box. Base Box is like a Template. You can create many VMs from it.

    Similarly, vagrant destroy destroys your VM. In this case all changes you made when inside it will be lost. But thats the cool idea that you can start from a base predefined state when you create a new VM.

I really like using it and have blogged about it.

In summary, it is a good wrapper over VirtualBox APIs and Commands. You can have a look at the VirtualBox commands to understand some of the capabilities better.

It really is too bad that even though the current docs for v1.1 looks better, it's much less complete than v1. The credo 'less is more' just doesn't work in the area of documentation...

I've found that when it comes to Vagrantfiles, the most complete overview is in the comments of a freshly created Vagrantfile, after initializing a vagrant project. It mentions parameters that are not currently in the documentation.

I'm not sure when it changed, but the current version (1.6.3) has a proper list of commands, and running vagrant list-commands gives an even more complete list:

box             manages boxes: installation, removal, etc.
connect         connect to a remotely shared Vagrant environment
destroy         stops and deletes all traces of the vagrant machine
docker-logs     outputs the logs from the Docker container
docker-run      run a one-off command in the context of a container
global-status   outputs status Vagrant environments for this user
halt            stops the vagrant machine
help            shows the help for a subcommand
init            initializes a new Vagrant environment by creating a Vagrantfile
list-commands   outputs all available Vagrant subcommands, even non-primary ones
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
rsync           syncs rsync synced folders to remote machine
rsync-auto      syncs rsync synced folders automatically when files change
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
version         prints current and latest Vagrant version

The only commands left out from the complete list when running vagrant by itself are the docker and rsync ones. On my system, anyway.

That seems to be the definitive answer, now.