opening Jupyter Lab in docker container - python

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>

Related

Running Jupyter notebook in docker image on Google Cloud

I'm running an Ubuntu 16.04 VM on Google Compute Engine. I've created a static IP address <my_static_ip_address> and my firewall settings allow tcp:80-8888.
I started the Jupyter server within the docker image with
jupyter notebook --ip=0.0.0.0 --port=8888 --no-browser --allow-root
and got this URL
http://0.0.0.0:8888/?token=8b26c453d278eae1da71b80f26a4ef8ea06734e5c636d897
I'm not able to access from external browser with http://<my_static_ip_address>:8888
What am I missing?
I started the Jupyter server within the docker image with
What was the docker command you ran? A common gotcha here would be not mapping a host port to a container port.
For example, if you did this:
docker run -p 8888 jupyter/notebook
Then docker would assign a random host port mapping to port 8888 in the container. In this case, you can see what port was mapped by running docker ps. The port will be much higher than 8888 though, so you won't be able to reach jupyter because your firewall will block the traffic.
What you probably want to do is go ahead and map a host port like so:
docker run -p 8888:8888 jupyter/notebook
This should map any traffic reaching the GCE host on port 8888 to port 8888 in your jupyter container.

Docker on Ubuntu 14.04 my browser is not starting after run command for Kaggle/python

In Kaggle/python docker on Ubuntu 14.04 my browser is not starting.Anyone has face this issue and resolution? I am using below command from terminal
"(sleep 3 && sensible-browser "http://127.0.0.1:8888")& docker run -v $PWD:/tmp/working -w=/tmp/working -p 8888:8888 --rm -it kaggle/python jupyter notebook --no-browser --ip=0.0.0.0 --notebook-dir=/tmp/working"
and when I go to Firefox web browser localhost:8888, it ain't show up nothing.
You can use datmo/kaggle:python to be able to run kaggle projects with jupyter notebook. After pulling the image, you can use code like this in the shell:
docker run --rm -it -p 8888:8888 -v ~/.:/home/ datmo/kaggle:python 'jupyter notebook'
This mounts the local directory onto the container having access to it.
Then, go to the browser and hit https://localhost:8888, and when I open a new kernel it's with Python 3.5. I don't recall doing anything special when pulling the image or setting up Docker.
You can find more information from here.
You can also try using datmo in order to easily setup environment and track machine learning projects to make experiments reproducible. You can run datmo task command as follows for setting up jupyter notebook,
datmo task run 'jupyter notebook' --port 8888
It sets up your project and files inside the environment to keep track of your progress.

Access Jupyter notebook running on Docker container

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'

How to watch xvfb session that's inside a docker on remote server from my local browser?

I'm running a docker (That I built on my own), that's docker running E2E tests.
The browser is up and running but I want to have another nice to have feature, I want the ability of watching the session online.
My docker run command is:
docker run -p 4444:4444 --name ${DOCKER_TAG_NAME}
-e Some_ENVs
-v Volume:Volume
--privileged
-d "{docker-registry}" >> /dev/null 2>&1
I'm able to export screenshots but in some cases it's not enough and the ability of watching what is the exact state of the test would be amazing.
I tried a lot of options but I came to a dead end, Any help would be great.
My tests are in Python 2.7
My Docker base is ubuntu:14.04
My environment is in AWS (If that's matter)
The docker runs on Ubuntu servers.
I know it a duplicate of this but no one answered him so...
There is a recent tool called Selenoid. It is launching browsers in Docker containers (i.e. headless as you require). It has a standalone UI capable to show live session screen via VNC. So you can launch multiple sessions in parallel and then look and even intercept actions happening in target browser. All this stuff perfectly works in cloud environment.
I have faced the same issue before with vnc, you need to know your xvfb/vnc in which port is using then open that port on you aws secuirty group once you done with that then you should be able to connect.
On my case i was starting selenium docker "https://github.com/elgalu/docker-selenium" and used this command to start the docker machine "docker run -d --name=grid -p 4444:24444 -p 5900:25900 \
-v /dev/shm:/dev/shm -e VNC_PASSWORD=hola \
-e SCREEN_WIDTH=1920 -e SCREEN_HEIGHT=1480 \
elgalu/selenium"
The VNC port as per the command is "5900" so i opened that port on instance security group, and connected using VNC viewer on port 5900

PyCharm add remote Python interpreter inside the Docker

So I have set up a docker on my laptop. I'm using Boot2Docker so I have one level of indirection to access the docker. In PyCharm, I can set a remote python interpreter via SSH but I'm not sure how to do it for dockers that can only be accessed via Boot2Docker?
Okay so to answer your question(s):
In PyCharm, I can set a remote python interpreter via SSH but I'm not sure how to do it for dockers that can only be accessed via Boot2Docker?
You need:
To ensure that you have SSH running in your container
There are many base images that include SSH. See: Dockerizing an SSH Daemon
Expose the SSH service to the Boot2Docker/VirtualBox VM.
docker run -d -p 2222:22 myimage ...
Setup PyCharm to connect to your Boot2Docker/VirtualBox VM.
boot2docker ip
Attaching to a running container is easy too!
$ boot2docker ssh
$ docker exec -i -t <cid> /bin/bash
Where <cid> is the Container ID or Name (if you used --name.

Categories