recently started using docker and tried to crate a container with jupyter lab, so it could run on a local host.
Since I have been using anaconda before it seems like that localhost:8888 is already taken, so I have tried to use another avaliable port. `docker run -p 8080:8080 <image_name>' created a link which web page with token authentification which gives me no chance to enter. Also it used same port 8888. Is there any other port to use so that both, anaconda and docker work together without errors?
Have you tried this?
TL;DR:
Run docker as
docker run -it -p 8888:8888 image:version
Then, inside your container, initialize Jupyter with:
jupyter notebook --ip 0.0.0.0 --no-browser --allow-root
Now you are supposedly able to access the notebook through your desktop browser on http://localhost:8888
The -p option to docker run takes two ports. First is the port on the host that you want to connect to, and second is the port within the container that the service is running on.
Assuming jupyter is running on port 8888 inside the container, and you want to access it on 8080 on your localhost, the command you are looking for would be:
docker run -p 8080:8888 <image_name>
or to run it interactively and clean up after itself:
docker run -it --rm 8080:8888 <image_name>
I have been trying to solve this for a couple of days and don't seem to find a way to do it. I have a raspberry pi in my local network which is running jupyter (port 8888) and a flask api (port 5000). I want to be able to access it remotely using another server. My setup and what I have until now is:
Server in GCP with static IP (let's say it's gcp.static.ip). I opened the ports 7003 and 7004 as udp.
Raspberry Pi in my home network with dynamic IP (can't have static IP) and jupyter and flask api on ports 8888 and 5000. I forwarded the ports with:
ssh -NR 7003:localhost:5000 -R 7004:localhost:88888 user#gcp.static.ip
Laptop in remote network. If I do the following ssh tunnel I can access the jupyter server at localhost:7004:
ssh -NL 7004:localhost:7004 user#gcp.static.ip
I can't seem to do the same for the flask API. If I ssh into the gcp server I can query the API at port 7003. How can I set the gcp server so that I can query the api with gcp.static.ip:APIPort and access jupyter in gcp.static.ip:JupyterPort.
Thanks a lot!
UPDATE: I'm able to query the api forwarding a TCP port. However, still want to know if this is possible without having to create another tunnel on my lapto.
Following this Link. Had to change /etc/ssh/sshd_config to set GatewayPorts to clientspecified and ssh tunnel with:
ssh -NR 0.0.0.0:7003:localhost:5000 user#gcp.static.ip
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.
I have a simple Python Flask based application in a docker image and I created a container with port mapping
docker run --name MypyFlskApp -p 5010:5000 flask-crud-rest-app
when i try to access MypyFlskApp container from host machine ("http://127.0.0.1:5010") i am getting error "Unable to connect to the remote server" but when i find container IP(http://172.19.247.234:5000) and tried the same then i get the response.
not sure why the port mapping is not working.
from host machine instead of 127.0.0.1 ( localhost) i have used VM IP address then my PythonFlask App started responding. Not sure why it is not able to access with 127.0.0.1(localhost)
I created a docker image with python libraries and Jupyter.
I start the container with the option -p 8888:8888, to link ports between host and container.
When I launch a Jupyter kernel inside the container, it is running on localhost:8888 (and does not find a browser). I used the command jupyter notebook
But from my host, what is the IP address I have to use to work with Jupyter in host's browser ?
With the command ifconfig, I find eth0, docker, wlan0, lo ...
Thanks !
You need to run your notebook on 0.0.0.0: jupyter notebook -i 0.0.0.0. Running on localhost make it available only from inside the container.
Host machine: docker run -it -p 8888:8888 image:version
Inside the Container : jupyter notebook --ip 0.0.0.0 --no-browser --allow-root
Host machine access this url : localhost:8888/tree
When you are logging in for the first time there will be a link displayed on the terminal to log on with a token.
The docker run command is mandatory to open a port for the container to allow the connection from a host browser, assigning the port to the docker container with -p, select your jupyter image from your docker images.
docker run -it -p 8888:8888 image:version
Inside the container launch the notebook assigning the port you opened:
jupyter notebook --ip 0.0.0.0 --port 8888 --no-browser --allow-root
Access the notebook through your desktops browser on http://localhost:8888
The notebook will prompt you for a token which was generated when you create the notebook.
To get the link to your Jupyter notebook server:
After your docker run command, a hyperlink should be automatically generated. It looks something like this: http://localhost:8888/?token=f3a8354eb82c92f5a12399fe1835bf8f31275f917928c8d2 :: /home/jovyan/work
If you want to get the link again later down the line, you can type docker exec -it <docker_container_name> jupyter notebook list.
The below is how I get it running on Windows 7 with docker toolbox.
If you are using docker toolbox, open up the Docker quickstart terminal, and note the IP here:
docker is configured to use the default machine with IP 192.168.99.100
For help getting started, check out the docs at https://docs.docker.com
Once you run the docker commands from the tensorflow installation website:
docker pull tensorflow/tensorflow # Download latest image
docker run -it -p 8888:8888 tensorflow/tensorflow # Start a Jupyter notebook server
You will receive a message like this:
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://127.0.0.1:8888/?token=d6e80acaf08e09853dc72f6b0f022b8225f94f
In the host, replace 127.0.0.1 with 192.168.99.100 and use the rest of that URL
You can use the command jupyter notebook --allow-root --ip[of your container] or give access to all ip using option --ip0.0.0.0.
As an alternative to building your own Docker image, you can also use the ML Workspace image. The ML Workspace is an open-source web IDE that combines Jupyter, VS Code, a Desktop GUI, and many other tools & libraries into one convenient Docker image. Deploying a single workspace instance is as simple as:
docker run -p 8080:8080 mltooling/ml-workspace:latest
All tools are accessible from the same port and integrated into the Jupyter UI. You can find further documentation here.
In the container you can run the following to make it available on your local machine (using your docker machine's ip address).
jupyter notebook --ip 0.0.0.0 --allow-root
You may not need to provide the --allow-root flag depending on your container's setup.
docker run -i -t -p 8888:8888 continuumio/anaconda3 /bin/bash -c "/opt/conda/bin/conda install jupyter -y --quiet && mkdir /opt/notebooks && /opt/conda/bin/jupyter notebook --notebook-dir=/opt/notebooks --ip='*' --port=8888 --no-browser --allow-root"
i had to add --allow-root to the command and now its running
The Makefile below encapsulates the previous answers and ensures that jupyter and docker agree on the port. And if I just click/copy the link provided by jupyter, that solves port mismatch problems.
To use, just make jupyter or make jupyter PORT=xxxx from the proper folder. Then click the link in the jupyter output.
Remote Containers
If your container is on a remote host (say an AWS EC2), then you'll also need to set up an ssh tunnel with the correct port. For example, on the local machine:
ssh -N -f -L localhost:8888:localhost:8888 username#remote-host
But at least that's only one place I can manually mismatch ports.
Makefile
# Set your default jupyter port here.
# Avoid 8888 if you run local notebooks on that!
PORT=8888
# Your app root in the container.
APP_DIR=/app
# The docker image to launch. *** SET TO YOUR image:version! ***
APP_TAG=image:version
jupyter: ##
## Launch jupyter notebook from our container, mapping two folders
## Local Container Notes
## -----------------------------------------------------
## ./data -> /data Put data here!
## ./notebooks -> /notebooks Find notebooks here!
## -----------------------------------------------------
## Arg: PORT - specify port [${PORT}]
docker run \
-p $(PORT):$(PORT) \
-v $(PWD)/notebooks/:$(APP_DIR)/notebooks/ \
-v $(PWD)/data:/data \
$(APP_TAG) \
jupyter notebook --ip 0.0.0.0 --port $(PORT) \
--no-browser --allow-root
Go in the Docker and check cat /etc/jupyter/jupyter_notebook_config.py :
You should see / add this line :
c.NotebookApp.allow_origin = 'https://colab.research.google.com'