vagrant package
vagrant package 介绍
vagrant package -h
Options:
–base NAME Name of a VM in virtualbox to package as a base box
–output NAME Name of the file to output
–include FILE… Additional files to package with the box
–vagrantfile FILE Vagrantfile to package with the box
-h, –help Print this help
可以用-h查看使用:
–base NAME :virtualbox程序里面的虚拟机的名称,不是box的名字也不是Vagrantfile里面的虚拟机名称.默认是打包当前目录下面的虚拟机
–output NAME :要打包成的box名称,不会自动添加.box后缀,要手动加.默认值package.box
** 由上面的介绍可以看出来,我们想要打包box,首先得知道虚拟机的名称,不是vagrant box list 出来的名称哦,这点要切记。
第一步:查看虚拟机名称
去到虚拟机安装目录,执行命令: vboxmanage list vms
这个名称为CentOS,也就是我们在vagrantfile里设置的,vagrantFile 部分设置如下:
config.vm.box = "CentOS_7"
config.vm.hostname = "CentOS"
config.vm.network "private_network", ip: "192.168.10.10",auto_config: true
config.vm.synced_folder "E:/workspaces/soundasia-app/", "/data/wwwroot/default/soundasia-app/"
config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
vb.memory = "1024"
vb.cpus = 2
vb.name = "CentOS"
end
是这里的vb.name
第二步:执行到处命令
到处目录需要去到你的vagrant目录下,也就是vagrantFile文件目录下
vagrant package –base CentOS –output CentOS.box
** 注意这里是- -base 不是-base, 后面跟的是vb的名称,即上面我们用命令查看的名称,后面的- - output(CSDN非得把我的- - 变- ,所以为了能看清楚,中间只能加个空格了,大家执行命令的时候不要加空格哦),后面跟的是要到处的box的名称,名称一定要加上.box哦。
这一步过后,你的文件夹下就多了一个CentOS.box文件,这个就是我们打包的box,给到其他小伙伴的用的话,直接就有了跟你一样的环境了。