简体   繁体   中英

Jupyter notebook from Docker container localhost not working

I'm trying to launch Jupyter notebook from a Docker container and the localhost just won't run on my browser.

Here's my script to run jupyter notebook

#!/bin/bash

# Usage:
# ./run_jupyter.sh [image]
#
# Parameters:
#   image - optional. A custom image to use instead of default. If it is given, 
#           we will not attemp to pull the latest image. This allows local image development.
#
# Container will be removed upon exit, but any jupyter settings and pakcages installed with
# pip install --user are kept in mlcourse.ai/home folder. 
# Remove them if you need a completely fresh image.
#
IMAGE=${1:-festline/mlcourse_ai}

#custom port
PORT=4545

# If we are called without a parameter to specify a new image, 
# let's make sure we are on the latest image
if [ $# -eq 0 ]; then
    echo "Will check for the latest image on the docker hub."
    docker pull $IMAGE
fi

exec docker run --rm -u $(id -u):$(id -g) -v "$PWD:/notebooks" -w /notebooks -e HOME=/notebooks/home -p $PORT:8888 $IMAGE jupyter-notebook --NotebookApp.ip=0.0.0.0 --NotebookApp.password_required=False --NotebookApp.token='' --NotebookApp.custom_display_url="http://localhost:$PORT"

# this allows for container to be created and persisted.
# which means that you can keep the changes you made, 
# i.e. if you installed more software with pip.
# 
# USER_ID=$(id -u) GROUP_ID=$(id -g) GROUP_NAME=$(id -gn) exec docker-compose -f docker/docker-compose.yaml up

When I run the script, this is what it shows on my terminal

[W 07:14:08.593 NotebookApp] All authentication is disabled.  Anyone who can connect to this server will be able to run code.
[I 07:14:08.629 NotebookApp] JupyterLab extension loaded from /opt/conda/lib/python3.6/site-packages/jupyterlab
[I 07:14:08.629 NotebookApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
[C 07:14:08.631 NotebookApp] Running as root is not recommended. Use --allow-root to bypass.

The complete output I get when I run the script is:

[W 03:18:04.430 NotebookApp] All authentication is disabled.  Anyone who can connect to this server will be able to run code.
[I 03:18:04.631 NotebookApp] JupyterLab extension loaded from /opt/conda/lib/python3.6/site-packages/jupyterlab
[I 03:18:04.631 NotebookApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
[I 03:18:04.635 NotebookApp] Serving notebooks from local directory: /notebooks
[I 03:18:04.635 NotebookApp] The Jupyter Notebook is running at:
[I 03:18:04.636 NotebookApp] http://localhost:4545/
[I 03:18:04.636 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 03:18:04.658 NotebookApp] No web browser found: could not locate runnable browser.

So what I did was copy " http://localhost:4545/ " above and paste it into the address box in my browser, and presto a Jupyter notebook comes listing the contents of the directory.

Hope this is useful.

I'm not sure why you're running it as root...

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