Reputation: 13335
I have an Ubuntu VM running on my windows machine (I'm using Vagrant with VirtualBox for that). I am running two docker containers in the VM, one a DB the other a web server. I want to proxy the web container through the host so that I can browse the web container from the windows machine.
Does docker help with this or do I need something like HAProxy on the VM?
Upvotes: 0
Views: 819
Reputation: 104005
There are differents ways to achieve this.
Lets firt assume you have the following container running on your Docker host:
docker run -d -p 80:80 tutum/hello-world
The -p
option tells Docker to open port 80
on the Docker host and forward traffic to port 80
of the Docker container.
In your Vagrantfile, you can assign a fixed IP to your Vagrant box by adding:
config.vm.network "private_network", ip: "176.16.0.3"
Then from Windows, open http://176.16.0.3/
If you don't want to assign a fixed IP address to your Vagrant box, you can instead forward port 80 from the Ubuntu box to port 80 of the Vagrant host (the Windows machine).
In your Vagrantfile, put
config.vm.network "forwarded_port", guest: 80, host: 80
Now, from the Windows machine, you can reach the webserver at http://localhost/.
Note that in your Docker container, your webserver MUST accept connections from the outside. In other words you need to bind to the special 0.0.0.0
network interface instead of just localhost
or 127.0.0.1
.
Upvotes: 3