如何得到一个Jupyter笔记本运行与docker运行时,它已经与docker撰写工作?



当我使用docker run命令使用Docker图像时,我无法在web浏览器中打开Jupyter Notebooks。我得到以下错误:

This site can’t be reached. The webpage at http://127.0.0.1:8888/?token=8543b16468608a7d26b8183256a97ebc3df41bf8838a3729 might be temporarily down or it may have moved permanently to a new web address. ERR_SOCKET_NOT_CONNECTED
到目前为止,我注意到它不适合我从Jupyter和Tensorflow docker图像。但是,如果我在Dockerfile中使用相同的图像标签并使用docker-compose命令,一切都可以正常工作。我还尝试构建图像,然后运行图像,但这也不起作用。我从Dockerfile构建:
docker build -t notebook .

,然后做

docker run --rm -p 8888:8888 -v $(pwd):/home/jovyan/work notebook

当我尝试使用Jupyter Notebook时,似乎只有使用docker-compose对我有效。有人知道为什么吗?

OS: Ubuntu 20.04 LTS

电脑型号HP ZBook

Docker运行命令和输出(不工作)

docker run --rm -p 8888:8888 -v $(pwd):/home/jovyan/work jupyter/minimal-notebook:notebook-6.4.3

终端

输出
WARN: Jupyter Notebook deprecation notice https://github.com/jupyter/docker-stacks#jupyter-notebook-deprecation-notice.
Executing the command: jupyter notebook
[I 14:17:21.359 NotebookApp] Writing notebook server cookie secret to /home/jovyan/.local/share/jupyter/runtime/notebook_cookie_secret
[W 2021-08-31 14:17:21.823 LabApp] 'ip' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2021-08-31 14:17:21.823 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2021-08-31 14:17:21.823 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2021-08-31 14:17:21.823 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[I 2021-08-31 14:17:21.830 LabApp] JupyterLab extension loaded from /opt/conda/lib/python3.9/site-packages/jupyterlab
[I 2021-08-31 14:17:21.831 LabApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
[I 14:17:21.835 NotebookApp] Serving notebooks from local directory: /home/jovyan
[I 14:17:21.835 NotebookApp] Jupyter Notebook 6.4.3 is running at:
[I 14:17:21.835 NotebookApp] http://7f3100bc5b0b:8888/?token=1eee2aee8a3fcda212f056af931a14b7dd5490846627c122
[I 14:17:21.835 NotebookApp]  or http://127.0.0.1:8888/?token=1eee2aee8a3fcda212f056af931a14b7dd5490846627c122
[I 14:17:21.835 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 14:17:21.838 NotebookApp] 

To access the notebook, open this file in a browser:
file:///home/jovyan/.local/share/jupyter/runtime/nbserver-8-open.html
Or copy and paste one of these URLs:
http://7f3100bc5b0b:8888/?token=1eee2aee8a3fcda212f056af931a14b7dd5490846627c122
or http://127.0.0.1:8888/?token=1eee2aee8a3fcda212f056af931a14b7dd5490846627c122

当我打开浏览器的链接,我得到

This site can’t be reached The webpage at http://127.0.0.1:8888/?token=8543b16468608a7d26b8183256a97ebc3df41bf8838a3729 might be temporarily down or it may have moved permanently to a new web address.
ERR_SOCKET_NOT_CONNECTED

Docker撰写命令及输出(works)

我有一个dock -compose。Yml文件

version: "3.2"
services:
jupyter:  # you can change this "jupyter" service to whatever you want.
build: 
context: ./docker-folder  # this is where the build directory is aka. Dockerfile.
image: compose-test
volumes:
- "./:/home/jovyan"
ports:
- "8888:8888"

docker-folder

文件夹中包含以下内容的Dockerfile
FROM jupyter/minimal-notebook:notebook-6.4.3
在终端中,我使用以下命令
docker-compose build && docker-compose up

jupyter笔记本在web浏览器中打开没有任何问题。终端中的输出如下

Creating network "desktop_default" with the default driver
Creating desktop_jupyter_1 ... done
Attaching to desktop_jupyter_1
jupyter_1  | WARN: Jupyter Notebook deprecation notice https://github.com/jupyter/docker-stacks#jupyter-notebook-deprecation-notice.
jupyter_1  | Executing the command: jupyter notebook
jupyter_1  | [W 2021-08-31 14:25:26.648 LabApp] 'ip' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
jupyter_1  | [W 2021-08-31 14:25:26.648 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
jupyter_1  | [W 2021-08-31 14:25:26.648 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
jupyter_1  | [W 2021-08-31 14:25:26.648 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
jupyter_1  | [I 2021-08-31 14:25:26.654 LabApp] JupyterLab extension loaded from /opt/conda/lib/python3.9/site-packages/jupyterlab
jupyter_1  | [I 2021-08-31 14:25:26.654 LabApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
jupyter_1  | [I 14:25:26.659 NotebookApp] Serving notebooks from local directory: /home/jovyan
jupyter_1  | [I 14:25:26.659 NotebookApp] Jupyter Notebook 6.4.3 is running at:
jupyter_1  | [I 14:25:26.659 NotebookApp] http://bf12dc888bfb:8888/?token=8376064cc9487deacb8182d280bb07dba6740a69cf890581
jupyter_1  | [I 14:25:26.659 NotebookApp]  or http://127.0.0.1:8888/?token=8376064cc9487deacb8182d280bb07dba6740a69cf890581
jupyter_1  | [I 14:25:26.659 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
jupyter_1  | [C 14:25:26.663 NotebookApp] 
jupyter_1  |     
jupyter_1  |     To access the notebook, open this file in a browser:
jupyter_1  |         file:///home/jovyan/.local/share/jupyter/runtime/nbserver-7-open.html
jupyter_1  |     Or copy and paste one of these URLs:
jupyter_1  |         http://bf12dc888bfb:8888/?token=8376064cc9487deacb8182d280bb07dba6740a69cf890581
jupyter_1  |      or http://127.0.0.1:8888/?token=8376064cc9487deacb8182d280bb07dba6740a69cf890581
jupyter_1  | [I 14:25:28.996 NotebookApp] 302 GET /?token=8376064cc9487deacb8182d280bb07dba6740a69cf890581 (172.23.0.1) 0.960000ms
jupyter_1  | /opt/conda/lib/python3.9/json/encoder.py:257: UserWarning: date_default is deprecated since jupyter_client 7.0.0. Use jupyter_client.jsonutil.json_default.
jupyter_1  |   return _iterencode(o, 0)

然后用

结束docker-compose down -v

回答:显然,这个问题是由我的VPN引起的(我使用Express VPN,但不确定是否也适用于其他VPN)。如果我打开电脑并执行docker run ...,一切都可以正常工作。如果我打开VPN,就会出现错误。即使我关闭VPN,错误也会继续发生。但是,如果我重新启动计算机并再次执行docker run命令,一切都完全正常。

我不知道为什么,但我从来没有得到错误,当我使用我的docker-compose文件,它总是工作。

最新更新