macos - 无法在 docker (mac) 中访问 jupyter notebook
问题描述
我想将 jupyter notebook 安装到我的 docker 映像中。在容器中安装并运行后,我无法从浏览器访问它。
这是我的最小设置:
Dockerfile:
FROM python:3.7.5
RUN pip install jupyterlab
EXPOSE 8888
CMD jupyter-lab --allow-root
命令
docker build -t my_image .
docker run -p 8888:8888 my_image
容器输出:
To access the server, open this file in a browser:
file:///root/.local/share/jupyter/runtime/jpserver-7-open.html
Or copy and paste one of these URLs:
http://localhost:8888/lab?token=e6b9a5dd573aabc52e6753e7b21f0daf6270e685055afa50
or http://127.0.0.1:8888/lab?token=e6b9a5dd573aabc52e6753e7b21f0daf6270e685055afa50
我尝试打开这些链接中的任何一个,并在浏览器中收到此消息:
This page isn’t working
localhost didn’t send any data.
ERR_EMPTY_RESPONSE
我究竟做错了什么?
解决方案
默认情况下,Jupyter 配置为仅侦听 localhost 接口,您需要将其配置为侦听 0.0.0.0(容器的 localhost 不是您的主机 localhost..)
将CMD
Dockerfile 中的行更改为CMD jupyter-lab notebook --ip 0.0.0.0 --port 8888 --allow-root
或jupyter_notebook_config.py
在容器/图像中编辑:
更改以 to 开头的c.NotebookApp.allow_origin
行c.NotebookApp.allow_origin = '*'
并更改以 to 开头的c.NotebookApp.ip
行c.NotebookApp.ip = '0.0.0.0'
使用此问题寻求帮助:为什么我无法访问远程 Jupyter Notebook 服务器?
推荐阅读
- flutter - 如何解决“VM Exception while processing transaction: out of gas”
- android - 将文档保存到外部存储时 PdfBox-Android EPERM(不允许操作)
- javascript - 获取 TypeError: expect(...).toBeInTheDocument 不是函数
- visual-studio-2019 - 为什么 Visual Studio 2019 安装程序无法在我的计算机上运行?
- flask - FLASK 在服务器上找不到请求的 URL
- list - 拆分列表并重复值
- ruby-on-rails - 'block in draw' 轨道 6 条路线
- python - 如何在已知点的方向上插入一个新点
- python - 使用 python 为 ascii 文件的每一行添加格式为 YY-MM-DD 的日期
- windows - 无法通过 Pkg.add("something") 安装 Julia 包