My running vagrant box (ubuntu, on a OS X Mavericks host) has been running fine.
I am trying to set up pgAdmin from the host, and am having trouble opening a new port for the sql traffic.
I added a line to my Vagrantfile (the last one):
config.vm.network "forwarded_port", guest: 3000, host: 8080 # http
config.vm.network :forwarded_port, guest: 35729, host: 35729
config.vm.network "forwarded_port", guest: 5432, host: 7001 # postgres
I ran vagrant provision and bounced the Vagrant box several times. When it reboots the new port forwarding is not listed:
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 3000 => 8080 (adapter 1)
default: 35729 => 35729 (adapter 1)
default: 22 => 2222 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
Curl gives a negative response also:
➜ ~ curl -v 'http://localhost:7001/'
* Adding handle: conn: 0x7fde1a004400
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fde1a004400) send_pipe: 1, recv_pipe: 0
* About to connect() to localhost port 7001 (#0)
* Trying ::1...
* Trying 127.0.0.1...
* Trying fe80::1...
* Failed connect to localhost:7001; Connection refused
* Closing connection 0
curl: (7) Failed connect to localhost:7001; Connection refused
Related posts:
Vagrant Port Forwarding not working
Cannot connect to Postgres running on VM from host machine using MD5 method
Vagrant forwarded ports allow you to access a port on your host machine and have all data forwarded to a port on the guest machine, over either TCP or UDP.
Default Network Interface If more than one network interface is available on the host machine, Vagrant will ask you to choose which interface the virtual machine should bridge to. A default interface can be specified by adding a :bridge clause to the network definition.
Since the 5432<-->7001 port mapping is not listed in the Vagrant up sequence, it's not happening.
I would try a vagrant reload
which is supposed to reload those part of the Vagrantfile again.
If that doesn't work, you could also try manually adding the port mapping, at least to confirm the connection to your application. The accepted answer for Change Vagrant port forwarding on a running system explains how to do that in the VirtualBox UI.
Another way to set up a temporary terminal, besides opening up the VirtualBox settings, is to use vagrant ssh
, with additional arguments given after the --
:
vagrant ssh -- -L 3000:localhost:3000
This will forward port 3000 on the host to port 3000 on the guest.
The first number is for the host. To forward port 7001 on the host to the default postgresql port on the guest:
vagrant ssh -- -L 7001:localhost:5432
This will only last as long as your ssh session. If ssh gets disconnected, run it again. To make it persist after restarts, add it to your Vagrantfile
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With