簡體   English   中英

來自 Docker 容器本地主機的 Jupyter 筆記本不起作用

[英]Jupyter notebook from Docker container localhost not working

我正在嘗試從 Docker 容器啟動 Jupyter 筆記本,但本地主機無法在我的瀏覽器上運行。

這是我運行 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

當我運行腳本時,這就是它在我的終端上顯示的內容

[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.

我運行腳本時得到的完整輸出是:

[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.

所以我所做的是復制上面的“ http://localhost:4545/ ”並將其粘貼到我瀏覽器的地址框中,然后一個 Jupyter notebook 來列出目錄的內容。

希望這是有用的。

我不確定你為什么以 root 身份運行它......

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM