Vagrant无法转发此VM上的指定端口

 helenheling2007895 发布于 2023-01-10 11:20

我有一个盒子配置文件使用Vagrant.现在我想将Vagrant用于另一个盒子(b2),但是它说bioiq的实例正在消耗转发的端口2222(它是).

现在,如果我用下面的配置b2,Vagrant仍然会尝试使用2222.

Vagrant.configure("2") do |config|

  config.vm.box = 'precise32'
  config.vm.box_url = 'http://files.vagrantup.com/precise32.box'

  config.vm.network :forwarded_port, guest: 22, host: 2323

  # Neither of these fix my problem 
  # config.vm.network :private_network, type: :dhcp 
  # config.vm.network :private_network, ip: "10.0.0.200"
end

我尝试了其他SO问题的各种方法来设置:forwarded_port(见这里和这里).我也试过这个谷歌集团的帖子,但没有用.我一直收到这条消息.

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 2222 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: 22, 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.

我不知道为什么Vagrant一​​直无视我的指示.发布的配置不起作用.有没有人克服过这个?

2 个回答
  • 在ssh端口的情况下,Vagrant自己解决端口冲突:

    ==> ubuntu64: Fixed port collision for 22 => 2222. Now on port 2200.
    

    但是,您仍然可以通过以下方式创建不可避免的碰撞:

      创建第一个vagrant env(它将为ssh获取端口2222)

      暂停那个env(vagrant suspend)

      创建第二个流浪汉env(它将再次获得端口2222,因为它现在未使用)

      尝试再次带来第一个环境 vagrant up

    您将收到现在收到的错误消息.

    解决方案是使用vagrant reload,让vagrant discard虚拟机状态(这意味着它将以困难的方式关闭它 - 所以如果你有任何未保存的工作那么要小心)并再次启动环境,解决路上的任何ssh端口冲突通过它自己.

    2023-01-10 11:22 回答
  • 我刚刚在当前版本的Mac OSX(10.9.4)和VirtualBox(4.3.14)上遇到问题,其中默认的ssh端口2222既未使用也未被绑定.它导致sanity检查ssh连接无限期地超时.

    这不是完全相同的问题,但明确的前向解决了它:

    config.vm.network :forwarded_port, guest: 22, host: 2201, id: "ssh", auto_correct: true
    

    这个建议来自对Vagrant GitHub 问题1740的评论.

    目前尚不清楚是否正在检测转发到22的端口或是否使用了ID,但它对我有用.

    2023-01-10 11:22 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有