Vagrant, Flask - the application does not work 10.10.10.10, 127.0.0.1

I run the application in my local box through Vagrant. The Python / Flask application starts and prints:

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

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

Question: My application is running, but at what IP address? I can't seem to find him. Do I need to modify some configuration files?

Thanks in advance.

+5
source share
4 answers

There are many ways to run a flash web application on a virtual machine (tramp driven). I think the following approach is quite flexible, because you do not need to deal with a different IP address. It also looks like you are running on a host machine.

There are two things you need to configure. In VagranFile, you need to 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, in the virtual machine, you must run the flash application on ip 0.0.0.0 , which means that the web application will serve any IP address. Read more about this topic → flash drive doc section External visible server

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

What is it. You should be able to connect to http://localhost:5000

+7
source

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 address of the guest with the port from which you are launching the application.

0
source

Syudo is right, but it took me 4 hours to realize that he forgot to mention that you also have to run:

vagrant halt and then vagrant up

so that your update to the roaming file really takes effect

0
source

In the latest version of Flask and python, you do not need to configure the vagrant file or do not require any changes to the python script. Just run the flask with --host

 flask run --host=192.168.10.80 
0
source

Source: https://habr.com/ru/post/1215482/


All Articles