Vagrant: The forwarded port to 8080 is already in use on the host machine.

I was trying to spin up a vagrant box while another box was already running. I did configure

config.vm.network :forwarded_port, guest: 80, host: 8082

but was getting
Vagrant port forwarding Issue

theos:$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Fixed port collision for 22 => 2222. Now on port 2200.
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 8080 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: 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.

The only other place where I had specified this port number while packing the vagrant box was in

~/.vagrant.d/boxes/CentOS-6.4-x86_64-latest/virtualbox/include/_Vagrantfile

Edited this _Vagrantfile and changed

Vagrant.configure("2") do |config|
  # Forward apache
  config.vm.network :forwarded_port, guest: 80, host: 8080
end

to

Vagrant.configure("2") do |config|
  # Forward apache
  # config.vm.network :forwarded_port, guest: 80, host: 8080
end

Just commented out the port forwarding string so that this port forwarding can be dealt with either by vagrant scripts or by overriding this in the Vagrantfile in the box directory being run.

2 thoughts on “Vagrant: The forwarded port to 8080 is already in use on the host machine.”

  1. Thanks for posting this valuable information. This was what exactly I was about looking for. I’m going to come back to this site for sure!

Leave a Reply

Your email address will not be published. Required fields are marked *