我有一些迷茫的VM(包括Mac和windows,都在运行linux)。我在Vagrant文件中定义了如下端口转发:
config.vm.network "forwarded_port", guest: 80, host: 9007当我第一次做vagrant up时,它工作得很好。但是,当我做一个vagrant reload或vagrant halt,然后是vagrant up时,我会得到这样的消息:
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 9007 is already in use
on the host machine.
To fix this, modify your current project's Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:
config.vm.network :forwarded_port, guest: 80, 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. You could
try 'vagrant reload' (equivalent of running a halt followed by an up)
so vagrant can attempt to auto-correct this upon booting. Be warned
that any unsaved work might be lost.然后,我必须更改端口,以打开VM,这是一个痛苦。我已经检查了netstat和lsof,似乎没有任何东西在使用该端口。我认为这可能是一个时间问题,过了一段时间,我可以使用端口,但即使在等待了许多小时后,我仍然会遇到错误。
这种情况发生在Mac和Windows环境中。有什么设置可以让我重用端口吗?
发布于 2017-08-24 07:04:14
我通常使用静态IP来避免端口转发问题。流浪汉有一个auto_correct功能来帮助解决这个问题。
在运行多台Vagrant机器时,通常会不知不觉地创建相互冲突的转发端口定义(例如,转发到端口8080的两个单独的Vagrant项目)。流浪者包括内置的机制,以检测和纠正,自动。 端口碰撞检测总是被完成的。迷航者将不允许您定义一个转发端口,其中主机上的端口似乎正在接受通信量或连接。 必须为每个转发端口手动启用端口碰撞自动校正,因为当端口发生时,这通常是令人惊讶的,并且可能导致Vagrant用户认为端口没有被正确转发。启用自动更正很容易: Vagrant.configure("2") do \config\ config.vm.network "forwarded_port",来宾: 80,主机: 8080,auto_correct: true end 最后一个设置为true的
:auto_correct参数告诉Vagrant自动更正任何冲突。在流浪者上或流浪者重新装载期间,vagrant将输出有关任何碰撞检测和自动校正的信息,以便您能够注意并相应地采取行动。
https://stackoverflow.com/questions/45851111
复制相似问题