0
votes

For example I have an app which run vagrant machines dynamically and expect some info from them will be sent through http to specific host machine port. So, my app listening specified port (http server) and I can't forward that port:

C:\node-vagrant-test-task>vagrant reload ==> default: Clearing any previously set forwarded ports... 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 project's Vagrantfile to use another port. Example, where '1234' would be replaced by a unique host port:

config.vm.network :forwarded_port, guest: 8080, 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.

1
You should change the forwarded port , you cannot force forward to a port, on which the host is already listening ontux
@deepak I can't just change it, because app inside vagrant guest will send data on specific address - localhost:8080 in my case. So, host machine listen that address. Maybe it will possible if host and guest will be in some kind of a network and will have different IPs and guest just will send info at specific <host-ip>:8080 address.Alendorff

1 Answers

0
votes

If you do not want to mess with forwarding port, the best is to use a static IP for the guest

you can do either private or public networks with a static IP

Vagrant.configure("2") do |config|
  config.vm.network "private_network", ip: "192.168.50.4"
end

or

Vagrant.configure("2") do |config|
  config.vm.network "public_network", ip: "192.168.50.4"
end

so you dont need to forward the 8080 port and can access your app directly on http://192.168.50.4:8080

If you need to then access the host machine for this guest, you can access it via 192.168.50.1