Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant, Flask — App not running on 10.10.10.10, 127.0.0.1

I'm running an app on my local box via Vagrant. The Python/Flask app launches and prints:

* Running on http://127.0.0.1:5000/ * Restarting with reloader

I found this https://github.com/makersquare/student-dev-box/wiki/Using-Vagrant-for-Development#testing-web-based-applications-in-vagrant which suggests that Vagrant apps run on 10.10.10.10 (not 127.0.0.1), but when I navigate to that IP address (port 5000), I get the same result: "This webpage is not available".

Question: my app is running, but on what IP address? I can't seem to find it. Do I need to modify some configuration files?

Thanks in advance.

like image 956
tmthyjames Avatar asked Mar 16 '15 22:03

tmthyjames


2 Answers

There are many ways how you could run flask web app on virtual machine (managed by vagrant). I think that following approach is quite flexible, because you don't have to deal with different ip address. Also it looks like you are developing on a host machine.

There are 2 things you need to configure. In VagranFile, you need configure port forwarding.

Vagrant.configure(2) do |config|
  # use default box
  config.vm.box = "ubuntu/trusty64"

  # forward port guest machine:5000 -> host machine:5000
  # port 5000 is default for flask web app
  config.vm.network "forwarded_port", guest: 5000, host: 5000
end

Then, on virtual machine, you should start flask app on ip 0.0.0.0 which means that web app will serve for any IP address. More on this topic -> flask doc section Externally Visible Server

if __name__ == "__main__":
    app.run("0.0.0.0", debug=True)

That's it. You should be able to connect to http://localhost:5000

like image 185
sjudǝʊ Avatar answered Nov 04 '22 08:11

sjudǝʊ


In the file where you call app.run, it should be

app.run(host='0.0.0.0', port=...

In the host OS, navigate to the IP of the guest with the port that you're running the app from.

like image 37
Celeo Avatar answered Nov 04 '22 09:11

Celeo