Vagrant 开发环境配置

需要安装的软件

  • Vagrant
  • provider

    • VirtualBox(Free, recommend)
    • VMware

    • AWS

常用命令

安装

安装、启动、进入虚拟机就参见这个链接吧。注意:

be careful about rm -rf /, since Vagrant shares a directory at /vagrant with the directory on the host containing your Vagrantfile
vagrant init <box-name-on-cloud> # 生成 Vagrantfile 文件
vagrant up [--provider=virtualbox|vmware_fusion|aws] # 下载、配置、启动虚拟机
vagrant ssh # 连接虚拟机
vagrant destroy
vagrant reload [--provision] # 重新载入配置
vagrant share # 通过 ngrok 内网穿透功能实现让全世界人可以访问虚拟机的服务
vagrant status # 查看虚拟机状态

搜索可用虚拟机镜像(box):Discover Vagrant Boxes – Vagrant Cloud

其他镜像:http://www.vagrantbox.es/

销毁

vagrant suspend # 休眠
vagrant halt # 关机
vagrant destroy # 关机并完全销毁所有相关资源

打包

vagrant package # 打包生成 package.box 文件
vagrant box add <vm-name> <box-file-path> # 添加box

自定义配置

配置都保存在 Vagrantfile 这个文件里。

(待续)

碰到的问题

VBoxManage path on OSX

/Applications/VirtualBox.app/Contents/MacOS/VBoxManage

Fix it by soft link

ln -s /Applications/VirtualBox.app/Contents/MacOS/VBoxManage /usr/local/bin/VBoxMange

vagrant up无反应 on Win7

因为windows上vagrant和virtualbox版本不兼容,参见在windows 7中vagrant up 无反应,没任何信息输出 成功解决,但是出现 0x80004005 错误。

E_FAIL (0x80004005) on Win7

返回 代码: E_FAIL (0x80004005)
组件: Machine
界面: IMachine {480cf695-2d8d-4256-9c7c-cce4184fa048}

Try to solve but failed, possible solutions:

  • vagrant up 出现错误:使用vagrant部署开发环境遇到的坑 – CSDN博客
  • Vagrant error on Windows 10 · Issue #195 · scotch-io/scotch-box

结论

本文介绍了vagrant和安装,配置,启动和打包。还有,垃圾windows!

标签:Vagrant 发布于:2019-11-03 19:50:59