1
votes

I have multiple docker containers running in vagrant box exposing various ports, but I forgot to forward these ports in Vagrantfile. Is it possible to forward the necessary ports without rebooting the machine (initializing all those containers would take a long while) and if not, what is the fastest method in that case?

Is there some organized way to handle port mappings in vagrant? It is pain to know all the needed ports beforehand. Especially when you must add new service to already running docker network inside vagrant, you would have to stop everything just to expose a port on vagrant host. And how to deal with situation where docker chooses random port from it's host for port forwarding? Is this just precluded when using vagrant? All feels so fragile to even little change.

2

2 Answers

1
votes

Another way is to open a terminal tab and run vagrant ssh with the ssh options needed to set up a tunnel. This is only temporary, so you still need to add the port forwarding to your Vagrantfile if you want it to persist.

vagrant ssh -- -L 5000:localhost:5000

This forwards port 5000 on the guest to port 5000 on the host.

0
votes

Yes you can. you will need to do it directly from VirtualBox

  1. Open VirtualBox
  2. Edit the settings of the VM you want to change
  3. Go to the Network tab
  4. Go to advanced then Forwarding Rules (or port forwarding, I got french version of vbox not sure whats the exact translation)
  5. Add your custom rules
  6. Apply

The forwarding rules is applied and you can connect to the guest port from your host