How to debug “Vagrant cannot forward the specified ports on this VM” message

后端 未结 13 2475
时光取名叫无心
时光取名叫无心 2020-12-25 10:33

I\'m trying to start a Vagrant instance and getting the following message:

Vagrant cannot forward the specified ports on this VM, since they
would collide wi         


        
相关标签:
13条回答
  • 2020-12-25 10:45

    Refer to my answer here: https://superuser.com/a/1610804/1252585

    Writing the content again:

    To list all of the LISTENING ports:

    $ netstat -a
    

    Use the following command to find the process ID of the process running on the desired port:

    $ netstat -ano | findstr :8080
    

    The result will be displayed as:

    $ netstat -ano | findstr :5000
      TCP    0.0.0.0:5000           0.0.0.0:0              LISTENING       18024
    

    Here, 18024 is the PID or Process ID.

    Then use the following command to kill the process on the post 8080:

    $ taskkill /PID 18024 /F
    

    or $ taskkill //PID 18024 //F

    Result will be displayed as:

    $ taskkill //PID 18024 //F
    SUCCESS: The process with PID 18024 has been terminated.
    
    0 讨论(0)
  • 2020-12-25 10:49

    You can see what vagrant instances are running on your machine by running

    $ vagrant global-status
    id       name    provider   state   directory
    ----------------------------------------------------------------------
    a20a0aa  default virtualbox saved   /Users/dude/Downloads/inst-MacOSX
    64bc939  default virtualbox saved   /Users/dude/svn/dev-vms/ubuntu14
    a94fb0a  default virtualbox running /Users/dude/svn/dev-vms/centos5
    

    If you don't see any VMs running, your conflict is not a vagrant box (that vagrant knows about). The next thing to do is to fire up the VirtualBox UI, and check to see if it has any instances running. If you don't want to run the UI, you can:

    ps -ef |grep VBox
    

    If you have VirtualBox instances running, they should be included in that output. You should be able to just kill processes that have VirtualBox in their output. One problem is that one of those processes seems to exist to do keep-alives. Just kill off the highest VirtualBox process. If you have a VirtualBox image running but vagrant doesn't know about it, some Vagrant directories may have been deleted manually, which means Vagrant loses track of the instance.

    0 讨论(0)
  • 2020-12-25 10:57

    I encountered this issue because I had a VM that was trying to run Postgres, and I had Postgres running on my local machine on port 5432.

    After vagrant resume, I got the error:

    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 5432 is already in use on the host machine.

    Look for what's running on port 5432:

    o-ets-webdeveloper:portal me$ lsof -i :5432
    COMMAND   PID     USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
    postgres 1389     me    5u  IPv6 0x681a62dc601cf1e3      0t0  TCP localhost:postgresql (LISTEN)
    postgres 1389     me    6u  IPv4 0x681a62dc6499362b      0t0  TCP localhost:postgresql (LISTEN)
    

    Turns out it's local Postgres, killing those processes allowed me to run vagrant resume successfully.

    0 讨论(0)
  • 2020-12-25 10:58

    You have to modify your Vagrantfile within your current directory including the following command:

    config.vm.network "forwarded_port", guest: 4567, host: <a port not used by your host machine>
    

    Keep in mind that there also a hidden folder (.vagrant.d/) containing settings for your vagrant environment as well as config files for your boxes. Usually this folder is in your home directory.

    e.g.

    ~/.vagrant.d/boxes/<your_box_name>/0/virtualbox/Vagrantfile
    

    Usually this file includes another Vagrantfile located in ~/.vagrant.d/boxes/<your_box_name>/0/virtualbox/include/_Vagrantfile

    You have to modify this file as well with the port-forwarding command

    0 讨论(0)
  • 2020-12-25 10:59

    Also note that (in Vagrant 1.6.4 at least) there is the folder ~/.vagrant.d/data/fp-leases, with files having names like 8080, 8081 etc. Erasing this folder contents helped me just now.

    0 讨论(0)
  • 2020-12-25 11:00

    My observation: I did not have any processes running on port 8000, so essentially the port forwarding did not work. Fix: Phil's answer provided a solution

    ~/.vagrant.d/boxes/ 
    

    The above path had other versions of vagrant files that listed the port 8000. Once I pruned them all using the below command I was able to run vagrant up successfully

    vagrant box remove [name] --all
    
    0 讨论(0)
提交回复
热议问题