简体   繁体   中英

Can't access jupyter notebook from docker

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?

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

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.

Here's what worked for me :

from another terminal run following command :

$ sudo docker ps
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                     NAMES
9137012fbde0        jupyter/base-notebook   "tini -g -- start-no…"   13 minutes ago      Up 13 minutes       0.0.0.0:10000->8888/tcp   happy_napier

As @atline mentioned, if you open browser in container, you could hit the url present on terminal. But most likely your browser is not running in the docker and you want to access Dockerized jupyter from non-Dockerized browser.

In your url change the host and port as below:

http://(c693a40d34b7 or 127.0.0.1):8888/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab

Will be changed to :

http://0.0.0.0:10000/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab

docker-machine ip didn't work for me but it helped me think about how I start my docker daemon.

If your docker daemon is running via minikube you can get the ip addr for your minikube cluster with

minikube ip

Use the ip addr you get from that in place of 127.0.0.1.

Try changing the port configuration in optional setting when running the new container to port 80 and call with http://127.0.0.1/?token=2e31ab3088fcf6a707480d456152c993606f26164fcc99ab (eliminating the port 8888 in the given address, as 80 is the default). That worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM