Docker - Connecting to Jupyter notebook - python

I am trying to run Jupyter notebook in docker for that I tried the command -
docker run -p 8888:8888 jupyter/scipy-notebook
Executing the command: jupyter notebook
[I 04:19:53.460 NotebookApp] Writing notebook server cookie secret to /home/jovyan/.local/share/jupyter/runtime/notebook_cookie_secret
[I 04:19:53.856 NotebookApp] JupyterLab extension loaded from /opt/conda/lib/python3.8/site-packages/jupyterlab
[I 04:19:53.856 NotebookApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
[I 04:19:53.859 NotebookApp] Serving notebooks from local directory: /home/jovyan
[I 04:19:53.859 NotebookApp] Jupyter Notebook 6.1.4 is running at:
[I 04:19:53.859 NotebookApp] http://ed93c6a6ff91:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c
[I 04:19:53.859 NotebookApp] or http://127.0.0.1:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c
[I 04:19:53.859 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 04:19:53.861 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://ed93c6a6ff91:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c
or http://127.0.0.1:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c
When I try to connect to the notebook (I tried three different browsers) using the following urls -
file:///home/jovyan/.local/share/jupyter/runtime/nbserver-6-open.html
OR
http://ed93c6a6ff91:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c
I get the error the site cannot be reached instantly with error code ERR_NAME_NOT_RESOLVED, while using the url -
http://127.0.0.1:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c
the browser would keep trying to connect for a while and then get ERR_CONNECTION_RESET
I tried to disable my VPN. I also tried setting the no_proxy variable using export no_proxy=127.0.0.1 but I was still not able to connect to the jupyter notebook.
OS - Manjaro Linux,
docker image -
REPOSITORY TAG IMAGE ID CREATED SIZE
jupyter/scipy-notebook latest b8f7562c1262 4 days ago 2.7GB
Any help or guidance on how I can troubleshoot and connect to the notebook would be much helpful.

Or copy and paste one of these URLs:
http://ed93c6a6ff91:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c
or http://127.0.0.1:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c
↑ That is your docker container IP and hostname. You need to connect using IP outside of docker container.
For example if your docker host (physical linux machine) IP is 192.168.0.100 try to access
http://192.168.0.100:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c
If you can't access in this case, try to set your host IP by running
docker run -p 192.168.0.100:8888:8888 jupyter/scipy-notebook
Edit 1. How to check opened ports.
Try to run
sudo netstat -ntpl | grep 8888
If you will see something like
tcp6 0 0 :::8888 :::* LISTEN 1234/docker-proxy
Or
tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 1234/docker-proxy
That means that your docker running fine and forwarding 8888 port to all local IPs (localhost including).
So if you can see open port but can't connect, firewall will be most likely cause.

Related

Connecting Jupyter notebook to Remote server

I have a linux server. On that I have installed Miniconda3 and other python packages along with Jupyter.
Now I want to run the notebook on the server and open in my browser.
For that, after installation of all packages, I do:
user#remoteip:$ jupyter notebook --no-browser --port=8890
Now I am copying the server IP address along with port to open it in my local browser.
http://remoteip:8890
However it doesn't open up anything.
I then followed all suggestions given in this SO answer by adding the required statements in the configuration file on the remote server anaconda and even local anaconda jupyter config file.
But it doesn't help at all.
After that I had to port forwarding as below in my local terminal:
user#localhost: ssh -N -f -L localhost:8890:localhost:8890 user#remoteip
And after that when I open
localhost:8890
now it opens up the notebook requiring the token to be entered and then it works.
My question is that do we need to do port forwarding everytime for us to open a notebook on remote server? One of my colleague said he didn't do any port forwarding and after first step itself, he was able to open the notebook with by typing
http://remoteip:8890
So I am not sure we need to do port forwarding for us to open the server jupyter notebook to open in browser or we can directly open the notebook with remoteip address?
Edit:
As per Alex's suggestion below, ran the following command after logging into dev server.
(ds_env) user#devvm1049:~$ jupyter notebook --no-mathjax --no-browser --ip 0.0.0.0 --port 8890
[I 23:49:56.032 NotebookApp] Serving notebooks from local directory: /home/user
[I 23:49:56.032 NotebookApp] The Jupyter Notebook is running at:
[I 23:49:56.032 NotebookApp] http://devvm.cdw.com:8890/
[I 23:49:56.032 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
Copied the above link to both chrome and Safari but it didn't open anything.
I have already done the above suggestions in this post. The only thing that has worked until now is doing Port tunneling but that is 3 steps everytime one has to open the jupyter on remote server.
Is this can be some port blocking issue? I tried pinging the remote server on laptop and it didn't give me any ping.
If you specify the --ip option when starting the server you can allow remote connection without port forwarding.
jupyter notebook --no-mathjax --no-browser --ip 0.0.0.0 --port 8890
# The --no-mathjax improves loading over slow connections
This is not recommended, though. See running a public jupyter notebook server. If you do this, I strongly recommend that you set a password, as described in that link.

How to log back in using SSH after logging out?

I logged out of my jupyter notebook which I had set up on my google cloud using SSH. Now, it needs password to log me in again.
To log back in (and get a password), I use the following code in the SSH window:
jupyter notebook --ip=0.0.0.0 --port=8888 --no-browser &
and I get this message:
I 18:06:11.509 NotebookApp] The port 8888 is already in use, trying another port.
[I 18:06:11.509 NotebookApp] The port 8889 is already in use, trying another port.
[I 18:06:11.509 NotebookApp] The port 8890 is already in use, trying another port.
[I 18:06:11.510 NotebookApp] The port 8891 is already in use, trying another port.
[I 18:06:11.510 NotebookApp] The port 8892 is already in use, trying another port.
[I 18:06:14.111 NotebookApp] jupyter_tensorboard extension loaded.
[I 18:06:14.188 NotebookApp] JupyterLab extension loaded from /usr/local/lib/python3.5/dist-packages/jupyterlab
[I 18:06:14.189 NotebookApp] JupyterLab application directory is /usr/local/share/jupyter/lab
[I 18:06:14.269 NotebookApp] Serving notebooks from local directory: /home/m_saljooghian
[I 18:06:14.269 NotebookApp] The Jupyter Notebook is running at:
[I 18:06:14.269 NotebookApp] http://(strongestf or 127.0.0.1):8827/?token=b996457bf3ce30f4da4d1f78f32e8592aa500bceef1b42e7
[I 18:06:14.269 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 18:06:14.273 NotebookApp]
To access the notebook, open this file in a browser:
file:///home/m_saljooghian/.local/share/jupyter/runtime/nbserver-3875-open.html
Or copy and paste one of these URLs:
http://(strongestf or 127.0.0.1):8827/?token=b996457bf3ce30f4da4d1f78f32e8592aa500bceef1b42e7
My initial port is 8888, but when I use the token for port 8888, it says "invalid credentials." when I try port 8827 (which is assigned by the SSH), the web page doesn't open. It says "This site can’t be reached."
I know my question is messy, but I did not know what else I should include. I appreciate your solutions or even suggestions to improve this question.
You have opened only the port 8888 in your GCP network settings so you will get connection refused on any other port. Try to kill your existing jupyter processes and free up port 8888 and try again

Jupyter on docker cannot automatically open up browser when it executed

I've had docker to use the jupyter notebook with tensorflow.
(My OS is window 10 so I use the Powershell.)
I want the jupyter to open the web browser automatically. When I try to initialize jupyter notebook.
For instance, I enter the command to start anaconda image (including tensorflow).
> docker run -it -v ~/tensorwork:/notebooks -p 8888:8888 anaconda3
And activate tensorflow
(base) root#e088a0e0e58e:/# conda activate tensorflow
After entering tensorflow kernel mode, I execute jupyter notebook.
(tensorflow) root#e088a0e0e58e:/# jupyter notebook --ip '*' --allow-root
[I 14:47:00.827 NotebookApp] [nb_conda_kernels] enabled, 4 kernels found
[W 14:47:01.080 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 14:47:01.214 NotebookApp] [nb_anacondacloud] enabled
[I 14:47:01.219 NotebookApp] [nb_conda] enabled
[I 14:47:01.265 NotebookApp] ✓ nbpresent HTML export ENABLED
[W 14:47:01.265 NotebookApp] ✗ nbpresent PDF export DISABLED: No module named 'nbbrowserpdf'
[I 14:47:01.268 NotebookApp] Serving notebooks from local directory: /
[I 14:47:01.269 NotebookApp] 0 active kernels
[I 14:47:01.269 NotebookApp] The Jupyter Notebook is running at:
[I 14:47:01.269 NotebookApp] http://[all ip addresses on your system]:8888/?token=55d0e39e50ff64ca52ab43516d06c96127704fb56de2d356
[I 14:47:01.269 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 14:47:01.270 NotebookApp] No web browser found: could not locate runnable browser.
[C 14:47:01.275 NotebookApp]
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8888/?token=55d0e39e50ff64ca52ab43516d06c96127704fb56de2d356
Execution of the jupyter notebook works well.
However, I manually enter the URL my browser to enter the notebook.
I guess this problem came from docker's feature. The container's file path needs to be connected to the local host so that jupyter can find the default web browser(chrome) that I use.
But how can I make it possible? I've already tried the editing config of jupyter notebook.
Before I execute jupyter notebook, I enter the command as following:
jupyter notebook --generate-config
vim ~/.jupyter/jupyter_notebook_config.py # or use your favorite editor
c.NotebookApp.browser = u'chrome'
(refer ; https://groups.google.com/a/continuum.io/forum/#!topic/anaconda/oXjbKNMyP30)
But the jupyter still said it cannot find any web browser. Help me please :)

Jupyter Notebook is not being opened in windows using Anaconda Prompt?

1) I tried to open Jupyter Notebook in Anaconda prompt.
Ananconda Prompt:
(C:\Users\sankarreddy\Anaconda3) C:\Users\sankarreddy>jupyter notebook
[I 21:24:52.854 NotebookApp] Serving notebooks from local directory: C:\Users\sankarreddy
[I 21:24:52.855 NotebookApp] 0 active kernels
[I 21:24:52.856 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/?token=fb39c20421e31cc66fddfd4fc00c7f64b8003bc53b83f461
[I 21:24:52.856 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 21:24:52.868 NotebookApp]
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8888/?token=fb39c20421e31cc66fddfd4fc00c7f64b8003bc53b83f461
2) My default browser is Google chrome and every time when I try to open the Jupyter notebook, the following is the result.
Result in the Browser(Google Chrome):
ERROR: Gateway Timeout
While trying to retrieve the URL http://localhost:8888/tree?token=4f3786890eceb91493af9bd6f4b07ae1ac6888c6172bbfca:
Connection refused
Your cache administrator is webmaster.
Generated Sun, 23 Jul 2017 14:01:21 GMT by 103.217.212.129 (Mikrotik HttpProxy)
3) I interrupted the process using 'Ctrl+C'.. it displays as follows.
[I 19:43:23.364 NotebookApp] Interrupted...
[I 19:43:23.365 NotebookApp] Shutting down kernels
I have googled about this issue, but had very little help which is of no use.
It seems like you're trying to open Jupyter Notebook in port 8888 as stated by the error message While trying to retrieve the URL http://localhost:8888/tree?token=4f3786890eceb91493af9bd6f4b07ae1ac6888c6172bbfca
But, when running Jupyter Notebook, there was an error message stating something else is running in port 8888 and it started the server in the next available port, which is 8889: [I 19:26:39.239 NotebookApp] The Jupyter Notebook is running at: http://localhos t:8889/?token=86664b50ba28f3bd3431554bc84d60d8bf4f3bf4209a4ecf
I'm not sure how to identify what is running on 8888, but you should definitely access your Jupyter Notebook on localhost:8889 .

How to use docker to connect with jupyter notebooks

I try to connect to jupyter notebooks from macos terminal, but when I use
python run_docker_jupyter.py
it returns me
Projects/data_science_course/mlcourse_open:/notebooks -w /notebooks festline/mlcourse_open jupyter
Command: jupyter
[I 14:12:55.078 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[W 14:12:55.101 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[W 14:12:55.101 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using authentication. This is highly insecure and not recommended.
[I 14:12:55.113 NotebookApp] Serving notebooks from local directory: /notebooks
[I 14:12:55.114 NotebookApp] 0 active kernels
[I 14:12:55.114 NotebookApp] The Jupyter Notebook is running at: http://[all ip addresses on your system]:4545/
[I 14:12:55.114 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
And I need to connect with local host, but after some command it returns me nothing. Or if I use docker ps or another docker command, it only prints this command in the terminal with sign [ before the command and after that it turn to next string. And that's all.
It's the first time I use docker, so I will be grateful for the help.
Try to use test your python first, e.t. try to run something as simple as:
python -c "print('test')"
you should have you "test" string as output.
Then try to check your docker:
issue:
$docker-machine ssh
if everything is okay you will be able to run
$docker ls
There is a known issue with kernel crashes that can be fixed by using Tini, I have attached links to a couple of gists that work very well.
Docker-compose yaml and Dockerfile

Categories