3

I have a flask application using bokeh that is running in a Docker container, and it works when I use it on local machines.

However, when I deploy it to a GCP instance, even though I can reach the server, I have some AjaxDataSource() objects which are failing to connect.

Some details,

  • All the machines, local and gcp vm are running Ubuntu 18.04
  • The flask app is started like this,

    app.run(host="0.0.0.0", port=6600, debug=False)

  • The Ajax route looks like this,

    http://127.0.0.1:6600/land/tmidemo/data_rate?name=ResultBaseKeysV1

  • The GCP firewall rules look like,

    Name                Type    Targets         Filters                 Protocols / ports       Action  Priority    Network
    tmiserver-egress    Egress  Apply to all    IP ranges: 0.0.0.0/0    tcp:6600    udp:6600    Allow   1000        default
    tmiserver-ingress   Ingress Apply to all    IP ranges: 0.0.0.0/0    tcp:6600    udp:6600    Allow   1000        default
    
  • The docker container is run like this,

    docker run --net tminet --hostname=TEST -p 6600:6600 -v $(pwd):/app/public --name myserver --rm myserver
    
  • I am not using a Bokeh server. The AjaxDataSource() calls point back to the flask application, not another (bokeh) server

There is a lot that works,

  • able to use the GCP external ip address and reach the server
  • going from web page to web page works, so flask routing is working

Whats NOT working is that Ajax() call which uses 127.0.0.1, although this DOES work when I run the container on a local machine.

The error I see in the inspect window is ERR_CONNECTION_REFUSED

The GCP instance hosts.conf DOES include a line for 127.0.0.1 localhost

I tried (from here) on the GCP VM instance, same result,

    iptables -A INPUT -i docker0 -j ACCEPT

I also tried (from here) changing the Docker run network to --net="host" and the result is identical.

I also tried adding --add-host localhost:127.0.0.1 to the Docker run command, same result.

I think the problem is configuring the GCP to know how to route a request to 127.0.0.1, but I don't know where to check, configure this, beyond what I have already done.

user9277612
  • 497
  • 4
  • 14
  • What is your command for starting Bokeh server? Do you use the **--allow-websocket-origin IP_ADDRESS** to white-list the IP_ADDRESS from which you access the Bokeh server? – Tony Mar 23 '19 at 08:49
  • Shouldn't your Ajax calls target your VM's external IP instead of localhost? – LundinCast Mar 23 '19 at 12:22
  • @tony I am not using a Bokeh server. – user9277612 Mar 23 '19 at 15:45
  • @LundinCast That might work, and I plan to test that as an experiment. Using the VM's external IP address is not a good idea because that IP address is not static. Using localhost (127.0.0.1) should work for any deployment, and it does on physical machines, just not on GCP VM. – user9277612 Mar 23 '19 at 15:48
  • Docker internal port mapping is dynamic but on your host machine you can use this approach to get all the info that you need: 1) In you "Docker run command" name your Docker container explicitly using ''**--name=YOUR_CONTAINER_NAME**'' 2) Use ''**docker port YOUR_CONTAINER_NAME**'' to show port mapping – Tony Mar 24 '19 at 10:09
  • @tony $ docker port tmiserver 6600/tcp -> 0.0.0.0:6600 – user9277612 Mar 24 '19 at 16:36

1 Answers1

1

I wasn't able to specifically resolve the issue I was having, but I tried a different approach to the URL for the AjaxDataSource() and it worked and I think a better approach...

I used Flask url_for() function to create a link to the route that the AjaxDataSource() needs and this worked. The resulting link looks something like,

    /land/tmidemo/data_rate/ResultBaseKeysV1

ie, no http://127.0.0.1, and this seems to work in all cases, my dev environment and GCP.

I think I tried this a long time ago and it didn't work, because I use "flask" URLs all over the place, but for some reason I thought I needed "http://127.0.0.1" for the Ajax stuff. Its works now.... moving on!

user9277612
  • 497
  • 4
  • 14