How can Vagrant move multiple ports on one computer?

I am wondering how to set up a vagrant file that will output a machine with two forwarded ports. This is my current Vagrantfile which redirects page 8080:

Vagrant.configure("2") do |config| config.vm.box = "precise32" config.vm.box_url = "http://files.vagrantup.com/precise32.box" config.vm.provider "virtualbox" config.vm.network :forwarded_port, guest: 8080, host: 8080 config.vm.provision :shell, :path => "start.sh", :args => "'/vagrant'" config.vm.network :public_network end 

Thank!

+55
vagrant portforwarding
Jul 12 '13 at 20:30
source share
4 answers

If you want to forward two ports, you can simply add another line:

 config.vm.network :forwarded_port, guest: 8080, host: 8080 config.vm.network :forwarded_port, guest: 5432, host: 5432 

The best way, in my opinion, is to set up a private network (or a host-only network), so you do not need to manually forward all ports.

See my post here: Forwarding the reverse port of vagrants?

Additional tips

If you use the :id function when defining entries :forward_port , you need to make sure that each one is unique. Otherwise, they will shrink with each other, and the last of them, as a rule, wins.

For example:

 config.vm.network "forwarded_port", guest: 8080, host: 8080, id: 'was_appserver_http' config.vm.network "forwarded_port", guest: 9043, host: 9043, id: 'ibm_console_http' config.vm.network "forwarded_port", guest: 9060, host: 9060, id: 'ibm_console_https' 
+88
Jul 12 '13 at 21:19
source share

You can forward as many ports as you want (if these hosts are not used ), follow these steps:

 # for Redis config.vm.network "forwarded_port", guest: 6379, host: 6379 # for HTTP config.vm.network "forwarded_port", guest: 80, host: 80 # for MySQL config.vm.network "forwarded_port", guest: 3306, host: 3306 

If you want to forward a range of ports, for loop can also be used as follows:

 for i in 81..89 config.vm.network :forwarded_port, guest: i, host: i end for i in 8080..8089 config.vm.network :forwarded_port, guest: i, host: i end 
+10
May 24 '16 at
source share

If you use the chef's kitchen, the ports are set in the .kitchen.yml file as follows:

 --- driver: name: vagrant network: - ["forwarded_port", {guest: 80, host: 40080}] - ["forwarded_port", {guest: 443, host: 40443}] provisioner: ... 

this will put the following lines in .kitchen / kitchen-vagrant / Vagrantfile:

 c.vm.network(:forwarded_port, {:guest=>80, :host=>40080}) c.vm.network(:forwarded_port, {:guest=>443, :host=>40443}) 

Remember to make the kitchen ruin and create the kitchen.

cm

http://www.jeeatwork.com/?p=76

https://github.com/test-kitchen/kitchen-vagrant#-network

https://docs.chef.io/config_yml_kitchen.html

+1
Mar 05 '17 at 23:00
source share

I could not access my application without a host argument:

 ng serve --host 0.0.0.0 
0
Jul 21 '19 at 16:19
source share



All Articles