View Tensorboard on Docker on Google Cloud

坚强是说给别人听的谎言 提交于 2019-12-17 17:54:52

问题


I am trying to display TensorBoard from TensorFlow on Docker on Google Cloud.

http://tensorflow.org/how_tos/summaries_and_tensorboard/index.md

tensorboard --logdir ./

I have Apache running on Google Cloud (it may be in my first container "ai-unicorn" Docker made its own container "docker-playground"). I can see the default page from Google Cloud at http://104.197.119.57/ .

I start TensorBoard on Google Cloud like this:

root@6cf64fd299f0:/# tensorboard --logdir ./ Starting TensorBoard on port 6006 (You can navigate to http://localhost:6006)

I tried the Google Cloud SSH option called "Open in browser window on custom port" using port 6006.

It displays: "We are unable to connect to the VM on port 6006."

What is the correct way to view TensorBoard from Google Cloud?


回答1:


By default, TensorBoard serves requests on 127.0.0.1, which is only accessible to processes running on the same machine. If you start TensorBoard with --host 0.0.0.0, it will also serve requests on the remote interfaces, so you should be able to connect to it remotely:

$ tensorboard --logdir ./ --host 0.0.0.0

Note that the "Open in browser window on custom port" will not connect you to the TensorBoard server - this option is used to connect to an SSH server on a non-standard port. The Google Cloud Platform docs have information on how to expose ports from your VM. You will need to allow connections on TCP port 6006 for remote access to your VM. You may also need to expose port 6006 from your Docker container, by following the instructions here.

EDIT: Added some step-by-step instructions to help with your Docker configuration. There are several issues here, and it's not possible to tell which one is failing.

  1. Configure port forwarding when you start your Docker container:

    (vm)$ docker run -p 0.0.0.0:7007:6006 -it b.gcr.io/tensorflow/tensorflow
    

    This forwards connections from port 7007 on your VM to 6006 in your Docker container. (Other values are possible.)

  2. Ensure that you can connect to TensorBoard from within the Docker container:

    (container)$ tensorboard --logdir ./ --host 0.0.0.0 --port 6006 &
    (container)$ curl http://localhost:6006/
    

    The second command should print some HTML to the console.

  3. In a shell on the VM, ensure that you can connect to the TensorBoard instance running in the container:

    (vm)$ curl http://localhost:7007/
    

    The command should print the same HTML to the console.

  4. Configure the Google Cloud firewall to allow your local client to connect to port 7007 on your VM.

    (client)$ gcloud compute firewall-rules create tensorboard --allow tcp:7007
    

    You should now be able to connect to TensorBoard in a web browser on your client.




回答2:


You do not have to use Docker to display the TensorBoard. But if you do want to use Docker, just run the TensorBoard inside of your Docker image.

The trick is to allow external access to the default TensorBoard tcp port 6006.

I tried the following working solution to display TensorBoard in my Google Cloud VM.

  1. ensure you pass the gcloud authentication:

    gcloud auth login

  2. allow public access to the tcp port 6006

    gcloud compute firewall-rules create tensorboard-port --allow tcp:6006

  3. Run TensorBoard on your VM

    tensorboard --logdir=workspace/train/

  4. Use external IP address to access the TensorBoard outside your VM:

    Open address http://your_vm_external IP:6006/,

    e.g. http://104.196.140.145:6006/, where 104.196.140.145 is the external IP address of my VM.




回答3:


another option is to use ngrok to tunnel. see: Can I use Tensorboard with Google Colab?

$ from jupyter notebook
ps = !ps -ax
is_tensorboard_running = len([f for f in ps if "tensorboard" in f ]) > 0

is_ngrok_running = len([f for f in ps if "ngrok" in f ]) > 0
print("tensorbord={}, ngrok={}".format(is_tensorboard_running, is_ngrok_running))

if not is_ngrok_running:  
#    grok should be installed in /content/ngrok
  get_ipython().system_raw('/content/ngrok http 6006 &')
  is_ngrok_running = True

# get public url for tensorboard
tensorboard_url = !curl -s http://localhost:4040/api/tunnels | python3 -c \
    "import sys, json; print(json.load(sys.stdin)['tunnels'][0]['public_url'])"    
print("tensorboard url=", tensorboard_url)


来源:https://stackoverflow.com/questions/33836728/view-tensorboard-on-docker-on-google-cloud

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!