我目前有一个vagrant
环境,其中每个VM都有从主机到来宾的端口转发规则设置。但是,此转发规则的问题在于,我不能同时使用类似的端口转发规则通过vagrant运行多个VM。
似乎我需要某种端口代理来处理这个问题。是否有一些已经融入vagrant / virtualbox的东西可以支持这个?
Traceback from Vagrant when I try running another VM with the same forwarding rules:
Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 8000 is already in use
on the host machine.
To fix this, modify your current projects Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:
config.vm.network :forwarded_port, guest: 8000, host: 1234
Sometimes, Vagrant will attempt to auto-correct this for you. In this
case, Vagrant was unable to. This is usually because the guest machine
is in a state which doesn't allow modifying port forwarding.
答案 0 :(得分:9)
您可以使用:auto_correct
参数进行端口定义,然后Vagrant将查找另一个(未使用的)端口:
Vagrant.configure("2") do |config|
config.vm.network "forwarded_port", guest: 80, host: 8080, auto_correct: true
end
有关详细信息,请参阅documentation。