Manjaro Linux环境下Docker运行Jupyter Notebook无法访问的技术求助
提问内容
我尝试在Docker环境中运行Jupyter Notebook,为此执行了如下命令:
docker run -p 8888:8888 jupyter/scipy-notebook Executing the command: jupyter notebook [I 04:19:53.460 NotebookApp] Writing notebook server cookie secret to /home/jovyan/.local/share/jupyter/runtime/notebook_cookie_secret [I 04:19:53.856 NotebookApp] JupyterLab extension loaded from /opt/conda/lib/python3.8/site-packages/jupyterlab [I 04:19:53.856 NotebookApp] JupyterLab application directory is /opt/conda/share/jupyter/lab [I 04:19:53.859 NotebookApp] Serving notebooks from local directory: /home/jovyan [I 04:19:53.859 NotebookApp] Jupyter Notebook 6.1.4 is running at: [I 04:19:53.859 NotebookApp] http://ed93c6a6ff91:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c [I 04:19:53.859 NotebookApp] or http://127.0.0.1:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c [I 04:19:53.859 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [C 04:19:53.861 NotebookApp] To access the notebook, open this file in a browser: file:///home/jovyan/.local/share/jupyter/runtime/nbserver-6-open.html Or copy and paste one of these URLs: http://ed93c6a6ff91:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c or http://127.0.0.1:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c
我尝试使用三种不同的浏览器,通过以下URL连接Notebook:
file:///home/jovyan/.local/share/jupyter/runtime/nbserver-6-open.html OR http://ed93c6a6ff91:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c
访问上述地址时,浏览器会立即提示无法访问站点,错误代码为 ERR_NAME_NOT_RESOLVED;而使用以下URL访问时:
http://127.0.0.1:8888/?token=40c97f5c727829f0c094449618af1cad30d56a8d5c252b6c
浏览器会持续尝试连接一段时间后,抛出 ERR_CONNECTION_RESET 错误。
我已尝试关闭VPN,也执行了 export no_proxy=127.0.0.1 命令设置 no_proxy 变量,但仍然无法连接到Jupyter Notebook。
操作系统:Manjaro Linux
使用的Docker镜像信息如下:
REPOSITORY TAG IMAGE ID CREATED SIZE jupyter/scipy-notebook latest b8f7562c1262 4 days ago 2.7GB
希望获得相关的故障排查指导,或顺利连接Jupyter Notebook的解决方案。
解决方法
错误原因说明
file:///home/jovyan/...是容器内部的本地文件路径,宿主机上不存在该文件,无法打开http://ed93c6a6ff91:8888是Docker分配给容器的内部主机名,仅Docker网络内的设备可解析,宿主机DNS无法识别,因此触发ERR_NAME_NOT_RESOLVED错误- ERR_CONNECTION_RESET的核心原因:默认启动的Jupyter Notebook绑定的是容器内部回环地址
127.0.0.1,而非所有可用地址0.0.0.0。Docker端口映射会将宿主机端口请求转发到容器的物理网卡接口,而非回环接口,因此请求会被Jupyter直接拒绝,触发连接重置。
直接可用的启动命令
在原有启动命令后追加参数,强制Jupyter监听所有接口:
docker run -p 8888:8888 jupyter/scipy-notebook start-notebook.sh --ip=0.0.0.0
启动后直接使用输出日志中http://127.0.0.1:8888/?token=xxx的地址访问即可。
后续排查步骤(若仍无法连接)
- 验证容器内监听状态:执行
docker exec <运行中的容器ID> netstat -tulpn | grep 8888,确认输出的监听地址为0.0.0.0:8888而非127.0.0.1:8888 - 宿主机跳过代理测试连通性:执行
curl --noproxy '*' http://127.0.0.1:8888/?token=<你的token>,若能正常返回HTML内容,说明服务运行正常,问题出在浏览器代理 - 检查浏览器代理设置,将
127.0.0.1、localhost加入代理排除列表,避免本地请求走代理
可选优化配置
如果需要将本地目录挂载到容器内做数据持久化,可在启动命令中追加卷挂载参数:
docker run -p 8888:8888 -v /你的本地工作目录:/home/jovyan/work jupyter/scipy-notebook start-notebook.sh --ip=0.0.0.0
内容的提问来源于stack exchange,提问作者Jack
相关产品推荐
相关产品推荐

