vagrant up
命令时,在配置过程的最后,我想将该Box打包成一个镜像保存在本地文件夹中,以便下一次需要重新构建时可以使用该镜像作为基础Box。我使用vagrant-triggers插件,在:up进程末尾放置代码。相关(简化)Vagrantfile:
pre_built_box_file_name = 'image.vagrant'
pre_built_box_path = 'file://' + File.join(Dir.pwd, pre_built_box_file_name)
pre_built_box_exists = File.file?(pre_built_box_path)
Vagrant.configure(2) do |config|
config.vm.box = 'ubuntu/trusty64'
config.vm.box_url = pre_built_box_path if pre_built_box_exists
config.trigger.after :up do
if not pre_built_box_exists
system("echo 'Building gett vagrant image for re-use...'; vagrant halt; vagrant package --output #{pre_built_box_file_name}; vagrant up;")
end
end
end
问题在于vagrant在当前(
vagrant up
)进程运行时锁定了机器:An action 'halt' was attempted on the machine 'gett',
but another process is already executing an action on the machine.
Vagrant locks each machine for access by only one process at a time.
Please wait until the other Vagrant process finishes modifying this
machine, then try again.
我知道在同一时间进行两个进程的配置或修改可能存在危险,但这是一个特殊情况,我可以确定配置已经完成。
我如何手动“解锁”vagrant机器以便我可以从config.trigger.after :up
中运行vagrant halt; vagrant package; vagrant up;
?
还是有一种方法可以启动vagrant up
而不锁定机器吗?
vagrant up && vagrant halt && vagrant package && vagrant up
呢? - Jon Burgessvagrant up
命令会处理掉vagrant box add ...
或者vagrant box remove ... && vagrant box add ...
这些命令,以防止因为重新构建而删除了image.vagrant
文件。也许我在这里过于复杂化了。 - Vigintas Labakojiskill -9 <PID>
。 - andilabs