从 Docker 运行 Jupyter 笔记本:curl:(56) 记录失败:对等方重置连接



我有一个简单的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"]

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

docker container run -d -p 8888:8888 -p 4040:4040 --name test_run my_custom_image

然后我检查日志以获取 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

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

curl http://127.0.0.1:8888/tree?token=7bf22f85e7b942b9936b1403523ba8c334a62bdd278376fc
curl: (56) Recv failure: Connection reset by peer

如果我运行一个docker container exec -it test_run bash并从那里运行卷曲,它就可以工作了

在主机上运行netstat -tupln

tcp6       0      0 :::8888                 :::*                    LISTEN      

在容器中运行netstat -tupln

tcp        0      0 127.0.0.1:8888          0.0.0.0:*               LISTEN      1/python

有什么提示吗?

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

最新更新