Forward ports through VM using vagrant-lxc
Closed this issue · 1 comments
Hey,
I'm currently setting up a local development environment on my mac which is running a Linux VM. On the VM, I'm using vagrant-lxc plugin to spin up containers.
Let's say I want to forward port 80 from the container to Linux VM port 8001 and I'd like to access VM's port 8001 from my mac.
I forward the port in container's Vagrantfile:
config.vm.network "forwarded_port", guest: 80, host: 8001
And when I run netstat -na | grep 8001
on Linux VM, I get:
tcp 0 0 127.0.0.1:8001 0.0.0.0:* LISTEN
But this means that I cannot connect to my VM port 8001 from my mac:
$ curl 192.168.56.99:8001/ -vvvv
* Trying 192.168.56.99...
* connect to 192.168.56.99 port 8001 failed: Connection refused
* Failed to connect to 192.168.56.99 port 8001: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 192.168.56.99 port 8001: Connection refused
However, when I comment out this line from lib/vagrant-lxc/action/forward_ports.rb
:
#params.unshift "--laddr=#{host_ip}" if host_ip
and do vagrant reload
for the container, then netstat -na | grep 8001
on Linux VM shows:
tcp 0 0 0.0.0.0:8001 0.0.0.0:* LISTEN
And then I can connect to my VM port 8001 from my mac:
$ curl 192.168.56.99:8001/
<!DOCTYPE html>
<html>
This fix is described in this tutorial under "Port forwarding" section:
http://taoofmac.com/space/HOWTO/Vagrant
Could this use case be somehow addressed?