Can't access jupyter notebook from docker

孤街醉人 提交于 2020-05-30 07:35:47

问题


I am trying to run a jupyter notebook created in Docker.

Firstly I run a container:

docker run -p 8888:8888 jupyter/tensorflow-notebook

What I get is:

[I 19:44:47.140 NotebookApp] Writing notebook server cookie secret to /home/jovyan/.local/share/jupyter/runtime/notebook_cookie_secret
[I 19:44:51.731 NotebookApp] JupyterLab extension loaded from /opt/conda/lib/python3.7/site-packages/jupyterlab
[I 19:44:51.732 NotebookApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
[I 19:44:51.742 NotebookApp] Serving notebooks from local directory: /home/jovyan
[I 19:44:51.743 NotebookApp] The Jupyter Notebook is running at:
[I 19:44:51.743 NotebookApp] http://(c693a40d34b7 or 127.0.0.1):8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab
[I 19:44:51.743 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 19:44:51.753 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///home/jovyan/.local/share/jupyter/runtime/nbserver-6-open.html
    Or copy and paste one of these URLs:
        http://(c693a40d34b7 or 127.0.0.1):8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab

But when I try to open Jupyter notebook on Chrome:

file:///home/jovyan/.local/share/jupyter/runtime/nbserver-6-open.html
or
http://c693a40d34b7:8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab

It is written that file was not found or that site can't be reached. What am I doing wrong?


回答1:


What I had to do was to get ip address of the docker-machine using command:

docker-machine ip

Then use the ip I got instead of the one given in the command:

Or copy and paste one of these URLs:
    http://(c693a40d34b7 or 127.0.0.1):8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab



回答2:


file:///home/jovyan/.local/share/jupyter/runtime/nbserver-6-open.html
or
http://c693a40d34b7:8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab

This just mean if you open browser in container, you could do above.

When you start it in container and want to open browser on host or other machine, you surely need to do some changes, in your case it should be next:

http://$(YOUR_DOCKER_HOST_IP):8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab

And if just open browser on docker host, then also could use:

http://localhost:8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab

Or

http://127.0.0.1:8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab

If other pc need to visit, you still had to specify the docker host ip.



来源:https://stackoverflow.com/questions/57064541/cant-access-jupyter-notebook-from-docker

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