Search code examples
linuxdockervagrantvirtual-machinevagrantfile

How can I access an NGINX web server running inside a Docker container on a virtual machine managed by Vagrant, from my Windows host machine?


I have set up the Vagrantfile to use a public network with IP address 192.168.1.10 :

# -*- mode: ruby -*-
# vi: set ft=ruby :


Vagrant.configure("2") do |config|

  config.vm.box = "laravel/homestead"


  config.vm.network "public_network", ip: "192.168.1.10"

 
  
  config.vm.provider "virtualbox" do |vb|
      vb.name = "Agent1"
  end
  config.vm.provision "docker" do |vb|

  end
  config.vm.hostname = "Agent1"
 
end

I have launched the Docker container with the command docker run -it -p 88:80 nginx to map port 80 inside the container to port 88 on the host machine. However, when I try to access the web server using URLs like 192.168.1.10:88, localhost:88, or 127.0.0.1:88 in my web browser, it doesn't work.

What could be causing this issue, and what URL should I use to access the NGINX web server from my Windows host machine?


Solution

  • You've not forwarded port 88 on the VM to your host.

    First check you can SSH into that machine and curl localhost:88