从 Docker 运行 Jupyter Notebook:curl:(56) Recv 失败:连接重置由对等方

Zac*_* R. 3 docker jupyter-notebook

我有一个简单的 Dockerfile

FROM ubuntu:latest

RUN pip install cython jupyter

EXPOSE 8888 4040

CMD ["jupyter", "notebook", "--ip=127.0.0.1", "--port=8888", "--allow-root", "--no-browser"]
Run Code Online (Sandbox Code Playgroud)

我构建它并启动一个这样的容器:

docker container run -d -p 8888:8888 -p 4040:4040 --name test_run my_custom_image
Run Code Online (Sandbox Code Playgroud)

然后我检查日志以获取 jupyter 登录令牌:

docker container logs test_run
...
Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://127.0.0.1:8888/?token=7bf22f85e7b942b9936b1403523ba8c334a62bdd278376fc
Run Code Online (Sandbox Code Playgroud)

然后我尝试卷曲链接,但我得到了这个:

curl http://127.0.0.1:8888/tree?token=7bf22f85e7b942b9936b1403523ba8c334a62bdd278376fc

curl: (56) Recv failure: Connection reset by peer
Run Code Online (Sandbox Code Playgroud)

如果我运行 adocker container exec -it test_run bash并从那里运行 curl,它就可以工作

netstat -tupln在主机上运行:

tcp6       0      0 :::8888                 :::*                    LISTEN      
Run Code Online (Sandbox Code Playgroud)

netstat -tupln在容器中运行:

tcp        0      0 127.0.0.1:8888          0.0.0.0:*               LISTEN      1/python
Run Code Online (Sandbox Code Playgroud)

有小费吗?

Zac*_* R. 6

更改--ip=127.0.0.1--ip=0.0.0.0,它解决了我的问题..