Running Jupyter notebook in Docker - python

I want to run jupyter in docker container. I am not able to launch the jupyter notebook. When I copy paste the URL given in the terminal.. server cannot be reached. Will appreciate any ideas to try

You are forwarding port 8080 in the docker run call with -p 8080:8080. But you also need to forward port 8888 by adding -p 8888:8888. More specifically, you want to run:
docker -it -p 8080:8080 -p 8888:8888 jupyter/minimal-notebook

First thing is Jupyter nootbook runs on port 8888. If you want to access the notebook on a diff port on your host you should map it like this -p 80:8888.
If you don't mind using the defaults, you should use run the following command.
Run this command: docker run -p 8888:8888 jupyter/minimal-notebook. Then
replace the host name in the url given in terminal with localhost like this
http://localhost:8888/\?token\=<TOKEN>\&token\=<TOKEN>
This should work.
Note: If you map it to a diff port, you should replace it in the url you get in the terminal. Ex. http://localhost:80/\?token\=<TOKEN>\&token\=<TOKEN>

Related

Access Jupyter notebook running on Docker container on server

I have installed jupyter on a running container.
I'm unable to access the jupyter from my localhost.
I did:
#Acess server
ssh data#tmp-server-prod
# on server
docker ps
f04ccccccc7 registry.gitlab.com/BNPworld/business-intelligence/jupyter_project:9ad9XXXXXXXXXXXXXXXXXXXXXXXXXXX8 "/bin/bash -c '/usr/" 7 weeks ago Up 7 weeks jupyter_project
#
docker run -it -p 8888:8888 registry.gitlab.com/BNPworld/business-intelligence/jupyter_project:9ad9XXXXXXXXXXXXXXXXXXXXXXXXXXX8
# access to container
docker container exec -it f04ccccccc7 bash
#inside container
jupyter notebook --ip 0.0.0.0 --no-browser --allow-root
**i got**
http://127.0.0.1:8888/?token=16125997dXXXXXXXXXXXXXXXXXXXXXXXXXX24cd5d99
when I copied to browser but it doesn't work.

Azure App Service: specifying docker run port on container side

I want to use scrapinghub/splash container on Azure App Service (Web App for Containers) on Linux.
But docker run command on deploy randomly changes the binding port of container side (see the log below, port 8961 is automatically assigned. this number varies every deploy)
2020-01-21 08:56:47.494 INFO - docker run -d -p 8961:8050 --name b2scraper-splash_3_d89ce1f2 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITES_PORT=8050 -e WEBSITE_SITE_NAME=b2scraper-splash -e WEBSITE_AUTH_ENABLED=False -e PORT=8050 -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=b2scraper-splash.azurewebsites.net -e WEBSITE_INSTANCE_ID=5446f93a2cbcb25300f091395c54ce738773ce47489c2818322ffabbc23e3413 scrapinghub/splash:latest python3 /app/bin/splash --proxy-profiles-path /etc/splash/proxy-profiles --js-profiles-path /etc/splash/js-profiles --filters-path /etc/splash/filters --lua-package-path "/etc/splash/lua_modules/?.lua" --disable-private-mode --port 8050
Changing host port binding is possible using WEBSITES_PORT, but seems no way to change container side.
Is there way to fix container-side port binding like -p 8050:80 or -p 8050:443 of docker run command?
e.g. Using the container on Azure Container Instances is possible, without changing service port 8050.
--publish in the docker run command creates a firewall rule which maps a container port to a port on the Docker host.
https://docs.docker.com/config/containers/container-networking/
For the command: docker run -d -p 8961:8050 imagename, TCP port 8050 in the container is mapped to 8961 on the Docker Host. On App Services, this docker run command cannot be changed. The container port (8050 in this case) can be set to a specific value using WEBSITES_PORT application setting.
That doesn´t work. you get 443 as port with HTTPS.
Neither EXPOSE XXXX, nor WEBSITES_PORT or PORT as configuration parameters...
You do see "docker run -d -p 8961:8050" in the logs, but it doesn´t matter to Azure when it comes to exposing the app...

How can i run a portia spider by its port?

I am trying to run a spider with portia in its docker version but i don't want to execute the spider using a terminal command like docker exec ... portiacrawl .... Is there any way I can run the spider, that is already created, by making a request at its localhost port and save it in an specific folder?
Something like:
https://localhost:9001/execute/spider_name/folder_path
Example of my own usage:
First what I do is run the container and leave it running, because i cant stop it for other reasons:
docker run -i -t -d --rm -v <PROJECTS_FOLDER>:/app/data/projects:rw -p 9001:9001 scrapinghub/portia
Next I execute the portiacrawl:
docker exec <CONTAINER_ID> portiacrawl <PROJECT_NAME_PATH> <SPIDER_NAME> -o /some/path/in/my/pc/<SPIDER_NAME>.json
Now, what i want is to replace the docker exec step with som http request to the localhost server that is running.
Thanks very much for your time
Yes, you can by doing a port mapping. While starting a docker container you wont have any ports published publicly or exposed internally unless you told docker to do so.
For example:
if you wish to expose a port internally (inside the docker network itself, you need to add EXPOSE in the dockerfile)
if you wish to publish a port publicly that can be access either through localhost or the public ip you can use -p option along with passing the ports so in your case it will be like this:
docker run -p 9001:9001 imagename
The command above will tell docker that you would like to do port mapping from 9001 (using localhost or any other interface) to 9001 (inside the container and you can change the ports according to your actual setup).
If you wish to expose it to localhost only you can change the command to something like this:
docker run -p 127.0.0.1:9001:9001 imagename
For more information check the following docs
According to the updated question, the other and safest way to accomplish this will be implementing an API inside portiacrawl that can be called through HTTP to do the needed tasks instead of using docker exec

Flask + Docker app - The container dies when i run docker run

I have an application with Dockerfile + docker-compose.
Dockerfile
docker-compose.yml
I have a CI, which creates an image from my dockerfile and send it to the hub.docker
Travis.yaml
When I drop this image on my cloud server I can not run this image by running the command below:
docker run -d -p 80:80 flask-example
because the container dies.
Besides the downloaded image from hub.docker after compiled by travis, will I need docker-compose on my server? Executing the command:
docker-compose up -d
To run the application? Or is there another way to do it?
Thanks guys.
running docker with -d flag detached your container, which mean that it runs in background.
Thus, you cannot see the error. Just remove this flag and you will see why it is dying.
From the link to your docker-compose file, it seems that port 80 is already in used (by frontend container) so maybe you can try using a different port?
(for example: docker run -d -p 8080:80 flask-example)
Second, you are right.
docker-compose is just another way to run your container. You don't have to use both.

Docker with Jupyter Notebook and Spark

I am trying to use docker to run Jupyter Notebook with spark , on PowerShell I am using the following command:
docker run --rm -h 0.0.0.0 -p 8888:8888 -e PYTHONHASHSEED=0 jupyter/all-spark-notebook
When I run that I get the following error:
Container must be run with group "root" to update passwd file
Any Ideas about how to fix it/ update group root password?

Categories