0
votes

I've been reading through many examples (both here and through various blogs and virtualbox/vagrant documentation) and at this point I think I should be able to do this.

What I ultimately would like to do is communicate with my docker daemon on my host machine and all the subsequent services I spin up arbitrarily.

To try to get this to work, I run the simple nginx container on my host and confirm it works:

$ docker run --name some-nginx -d -p 8080:80 docker.io/library/nginx:1.17.9
$ curl localhost:8080
> Welcome to nginx!

In my Vagrantfile I've define my host-only network:

config.vm.network "private_network", ip: "192.168.50.4",
  virtualbox__intnet: true

Now in my guest vagrant box, I expect that I should be able to access this same port:

$ curl localhost:8080
> curl: (7) Failed to connect to localhost port 8080: Connection refused

$ curl 127.0.0.1:8080
> curl: (7) Failed to connect to 127.0.0.1 port 8080: Connection refused

$ curl 192.168.50.4:8080 # I hope not, but maybe this will work?
> curl: (7) Failed to connect to 192.168.50.4 port 8080: Connection refused
1

1 Answers

0
votes

If you're "inside" the Vagrant guest machine, localhost will be the local loopback adapter of THAT machine and not of your host.

In VirtualBox virtualization, which you are using, you can always connect to services running on your hosts' localhost via the 10.0.2.2 address. See: https://www.virtualbox.org/manual/ch06.html#network_nat

So in your case, with the web server running on port 8080 on your host, using

curl 10.0.2.2:8080

would mean success!