Unable to access local development server of Google Cloud SDK for Python from Vagrant

Viewed 97

I am running local development server in a Vagrant box and trying to open it in Chrome(host machine). But it fails to open in the host machine. Using the curl on localhost:7000 in the guest machine returns the HTML content. This is my Vagrant file

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

Vagrant.configure(2) do |config|

  config.vm.box = "ubuntu/xenial64"
  config.vm.provision :shell, path: "setup_dev_env.sh"

  config.vm.box_check_update = false

  config.vm.network "forwarded_port", guest: 7080, host: 7080, host_ip: "127.0.0.1"
  config.vm.network "forwarded_port", guest: 7000, host: 7000, host_ip: "127.0.0.1"

  config.vm.synced_folder "SOME_PATH", "/home/vagrant/code"

  config.vm.provider "virtualbox" do |vb|
    vb.gui = false
    vb.memory = "4096"
  end
end

Command to run the server(guest machine):

python /home/vagrant/code/google-cloud-sdk/platform/google_appengine/dev_appserver.py PATH_TO_app.yaml --port=7080 --admin_port=7000  --datastore_path=~/BLAH.db
1 Answers

You need to add the following when running your command (https://cloud.google.com/appengine/docs/standard/python3/tools/local-devserver-command)

--host=...

The host address to use for the server. You may need to set this to be able to access the development server from another computer on your network. An address of 0.0.0.0 allows both localhost access and IP or hostname access. Default is localhost.

In your case as running in vagrant, you need to make sure its bound to 0.0.0.0

python /home/vagrant/code/google-cloud-sdk/platform/google_appengine/dev_appserver.py \
PATH_TO_app.yaml \
--host=0.0.0.0 --port=7080 --admin_port=7000  --datastore_path=~/BLAH.db
Related